codescracker


c++

C++ Program to Convert Decimal to Octal



« Previous Program Next Program »


Decimal to Octal Conversion in C++

To convert decimal number to octal number in C++ programming, you have to ask to the user to enter the decimal number to convert it into octal number to display the equivalent value in octal format as shown here in the following program.

C++ Programming Code to Convert Decimal to Octal

Following C++ program ask to the user to enter any number in decimal to convert it into octal, then display the result on the screen :

/* C++ Program - Decimal to Octal Conversion */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	long int decnum, rem, quot;
	int i=1, j, octnum[100];
	cout<<"Enter any decimal number : ";
	cin>>decnum;
	quot=decnum;
	while(quot!=0)
	{
		octnum[i++]=quot%8;
		quot=quot/8;
	}
	cout<<"Equivalent octal value of "<<decnum<<" is : \n";
	for(j=i-1; j>0; j--)
	{
		cout<<octnum[j];
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program convert decimal to octal

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test