🔄📚Intermediate
Decimal to Octal Conversion
Convert decimal to octal
Convert decimal to octal by repeatedly dividing by 8.
Program Code
decimal_octal.c
C
1#include <stdio.h>23int main() {4 int decimal, octal[32], i = 0;5 6 printf("Enter a decimal number: ");7 scanf("%d", &decimal);8 9 int original = decimal;10 11 while (decimal > 0) {12 octal[i] = decimal % 8;13 decimal /= 8;14 i++;15 }16 17 printf("Octal of %d: ", original);18 for (int j = i - 1; j >= 0; j--) {19 printf("%d", octal[j]);20 }21 printf("\n");22 23 // Using printf format specifier24 printf("Using %%o: %o\n", original);25 26 return 0;27}Output
Enter a decimal number: 65
Octal of 65: 101
Using %o: 101
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials