dec_to_bin

 #include <iostream>

#include <cmath>

#include <iomanip>

using namespace std;

int main() {

    // Write C++ code here

    int n,bin=0,i=0,count=0;

    cin>>n;

    do{

        

        int div_result=n%2;

        //cout<<div_result<<endl;

        bin=bin+(div_result*pow(10,i));

        n=n/2;

        i=i+1;

        count=count+1;

    }

    

    while(n/2!=0);

    //cout<<count<<endl;

    if (n==0){

        cout<<0;

    }

    else{

    cout<<setprecision(99999999) <<pow(10,count)+bin;

    return 0;

    }

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings