How to convert a decimal number to binary number in C++ Program

CWC
0 Min Read

How to convert a decimal number to binary number in C++ Program

#include
#include
using namespace std;
int main() 
{ 
int d,n,i,j,a[50]; 
cout<<"Enter a number:"; cin>>n; 
cout<<"\nThe binary conversion of "<<n<<" is 1"; for(i=1;n!=1;++i) { d=n%2; a[i]=d; n=n/2; } for(j=i-1;j>0;--j) cout<<a[j]; 
return 0; 
} 
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version