Write a program in C++ to convert an octal number into binary


#include <iostream>
using namespace std;
void main()
{

     long int n1, n5,p=1;
     long int dec=0,i=1,j,d;
     long int binno=0;
     cout<<"Convert Octal to Binary:\n ";
cout<<"Input an octal number (using digit 0 - 7) :";
cin>>n1;
n5=n1;
for (j=n1;j>0;j=j/10)
{
          d = j % 10;
            if(i==1)
                  p=p*1;
            else
                 p=p*8;

  dec=dec+(d*p);
  i++;
}
     i=1;

      for(j=dec;j>0;j=j/2)
       {
        binno=binno+(dec % 2)*i;
        i=i*10;
        dec=dec/2;
       }
        cout<<"\nThe Octal Number : "<<n5<<"\nThe equivalent Binary  Number :"<< binno<<endl;
         system ("pause");
}


Test Data :
Input an octal number (using digit 0 - 7) :57
Expected Output :
The Octal Number : 57
The equivalent Binary Number : 101111
Write a program in C++ to convert an octal number into binary  Write a program in C++ to convert an octal number into binary Reviewed by Unknown on June 20, 2017 Rating: 5

No comments:

Powered by Blogger.