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

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