Write a C++ program to convert given decimal number into its binary conversion.

Program Code:
#include<iostream>
using namespace std;
int main()
{
int deci, rem, q;
int binary[150];
int i=1, j;

cout<<"Enter any decimal number : ";
cin>>deci;
cout<<endl;
q = deci;
while(q != 0)
{
binary[i++] = q % 2;
q = q / 2;
}
cout<<"Equivalent binary value of "<<deci<<" : ";
for(j=i-1; j>0; j--)
{
cout<<binary[j];
}
return 0;
}

The program code is tested on www.jdoodle.com
Output:
Enter any decimal number : 45
Equivalent binary value of 45 : 101101


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: