C Programming Code Examples C > Conversions Code Examples Program to Convert Decimal number to Octal Number Program to Convert Decimal number to Octal Number Accept the given decimal number If the number is less than 8 the octal number is the same If the number > 7 then Divide the number with 8 Write down the remainder Do steps 3 and 4 with the quotient till that quotient is less than 8 Write the remainders in reverse order (bottom to top) The resultant is the equivalent octal number to the given decimal number #include<stdio.h> #include<conio.h> #include<math.h> void dectooct(long int number) // Function Definition { long int rem[50],dectooct=0,length=0; while(number>0) { rem[dectooct]=number%8; number=number/8; dectooct++; length++; } printf("nOctal number : "); for(dectooct=length-1;dectooct>=0;dectooct--) printf("%ld",rem[dectooct]); } //================================================ void main() { long int number; clrscr(); printf("Enter the decimal number : "); scanf("%ld",&number); dectooct(number); // Calling function getch(); }