C Programming Code Examples C > For Loops and While Loops Code Examples C program to convert Decimal to Octal number system C program to convert Decimal to Octal number system Write a C program to input decimal number from user and convert to octal number system. How to convert from decimal number system to octal number system in C programming. Decimal number system Decimal number system is a base 10 number system. Decimal number system uses 10 symbols to represent all numbers i.e. 0123456789. Octal number system Octal number system is a base 8 number system. Octal number system uses 8 symbols to represent all numbers i.e. 01234567 Algorithm to convert decimal to octal Algorithm Decimal to Octal conversion begin: read(decimal); octal = 0; place = 1; rem = 0; While (decimal > 0) do begin: rem = decimal % 8; octal = (rem * place) + octal; place = place * 10; decimal = decimal / 8; end; print('Octal number' octal); end; #include <stdio.h> int main() { long long decimal, tempDecimal, octal; int i, rem, place = 1; octal = 0; /* Input decimal number from user */ printf("Enter any decimal number: "); scanf("%lld", &decimal); tempDecimal = decimal; /* Decimal to octal conversion */ while(tempDecimal > 0) { rem = tempDecimal % 8; octal = (rem * place) + octal; tempDecimal /= 8; place *= 10; } printf("\nDecimal number = %lld\n", decimal); printf("Octal number = %lld", octal); return 0; }