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





Post A Comment:
0 comments: