Decimal to octal conversion in C++ by R4R Team

Decimal number:
Consists of 10 elements
range : 0 to 9

Octal number :
Consists of 8 elements
range : 0 to 7

Decimal to octal conversion:
Example-
Decimal number is 7
Octal number is 7
Decimal number is 41
Octal number is 15

program:

#include< iostream>
int main() {
int n,num=0;
cout<<"Enter decimal number"<< endl;
cin>>n;
while(n)
{
num=num*10+n%8;
n=n/8;
}
cout<<"It's Octal is "<< num<< endl;
}


output-

Enter decimal number
10
It's Octal is 21

Enter decimal number
41
It's Octal is 15

-In this program, we take an input of decimal number and find its octal equivalent.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!