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

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

   int n, i, j, ocno=0,dn;
     cout<<"Convert Decimal to Octal:\n ";
     cout<<"Enter a number to convert : ";
     cin>>n;
     dn=n;
     i=1;

      for(j=n;j>0;j=j/8)
       {
        ocno=ocno+(j % 8)*i;
        i=i*10;
        n=n/8;
       }
   
     cout<<"\nThe Octal of "<<dn<<"is"<<ocno<<endl ;
         system ("pause");
}



Test Data :
Enter a number to convert : 79
Expected Output :
The Octal of 79 is 117.
Write a program in C++ to convert a decimal number into octal without using an array. . Write a program in C++ to convert a decimal number into octal without using an array. . Reviewed by Unknown on June 11, 2017 Rating: 5

No comments:

Powered by Blogger.