codescracker


c

C Program to Convert Binary to Octal Number



« Previous Program Next Program »


Binary to Octal Conversion in C

To convert binary number to octal number in C programming, you have to ask to the user to enter binary number to convert it into octal number to display the equivalent value in octal.

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 Conversion */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	long int binnum, rem, quot;
	int octnum[100], i=1, j;
	clrscr();
	printf("Enter any binary number : ");
	scanf("%ld",&binnum);
	quot=binnum;
	while(quot!=0)
	{
		octnum[i++]=quot%8;
		quot=quot/8;
	}
	printf("Equivalent octal value of %d :\n",binnum);
	for(j=i-1; j>0; j--)
	{
		printf("%d",octnum[j]);
	}
	getch();
}

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

c program convert binary to octal

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test