Write a program in C++ to convert a decimal number into binary without using an array. .

#include <iostream>
using namespace std;
void main()
{
     int n, i, j, binno=0,dn;
     cout<<"\n\nConvert Decimal to Binary:\n ";
     cout<<"-------------------------\n";

     cout<<"Enter a number to convert : ";
     cin>>n;

     dn=n;
     i=1;

      for(j=n;j>0;j=j/2)
       {
        binno=binno+(n%2)*i;
        i=i*10;
        n=n/2;
       }
   
     cout<<"\nThe Binary of "<<dn<<"  is \n"<<binno;
 

      system ("pause");
}


Test Data : 
Enter a number to convert : 25 
Expected Output :
The Binary of 25 is 11001.

Write a program in C++ to convert a decimal number into binary without using an array. . Write a program in C++ to convert a decimal number into binary without using an array. . Reviewed by Unknown on June 11, 2017 Rating: 5

No comments:

Powered by Blogger.