Search This Blog

Program to Convert Decimal to Octal Number - Decimal to Octal converter

This is a program to convert a number in decimal (base 10) number system to octal number system. In octal number system, numbers are represented with base 8. That is, the digits are 0 to 7. The following program converts decimal numbers to octal.


#include<stdio.h>
#include<string.h>

int DecToOct(int dec)
{
int oct=0;
int i=1,tnum,rem;
tnum=dec;
while(tnum!=0)
{
rem=tnum%8;
oct=i*rem+oct;
tnum/=8;
i=i*10;
}
return(oct);
}


void main()
{
int inputnum;
printf("\nEnter the decimal number\n");
scanf("%d",&inputnum);
printf("Corresponding octal number is: %d",DecToOct(inputnum));
}

No comments: