codescracker


c++

C++ Program to Convert Binary to Octal



« Previous Program Next Program »


Binary to Octal in C++

To convert binary to octal in C++ Programming, you have to ask to the user to enter any number in binary to convert it into octal to display the equivalent value in octal on the screen as shown in the following program.

C++ Programming Code to Convert Binary to Octal

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

/* C++ Program - Binary to Octal */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	long int binnum, rem, quot;
	int octnum[100], i=1, j;
	cout<<"Enter any binary number : ";
	cin>>binnum;
	quot=binnum;
	while(quot!=0)
	{
		octnum[i++]=quot%8;
		quot=quot/8;
	}
	cout<<"Equivalent octal value of "<<binnum<<" :\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 number from binary 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