Decimal to octal conversion C program

Simple C program for decimal to octal conversion


/* C Program for decimal to octal conversion */
#include<stdio.h>
int main()
{
     int decimal,octal=0,p=1,num;
	printf("Enter a decimal number: ");
	scanf("%d",&decimal);
	num=decimal;
 
	while(num!=0)
	{
		octal=octal+(num%8)*p;
		p=p*10;
		num=num/8;
	}
 
	printf("%d in octal = %d",decimal,octal);
 
	return 0;
}

Popular posts from this blog