Write a C++ program to convert a Decimal number to its corresponding Octal number.

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

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

The program output is tested on www.jdoodle.com
Output:
Enter any decimal number : 45
Equivalent octal value of 45 is : 55


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: