🔄📚Intermediate

Octal to Decimal Conversion

Convert octal to decimal

Convert octal (base 8) to decimal (base 10).

Program Code

octal_to_decimal.c
C
1#include <stdio.h>
2#include <math.h>
3
4int main() {
5 int octal, decimal = 0, i = 0;
6
7 printf("Enter an octal number: ");
8 scanf("%d", &octal);
9
10 int original = octal;
11
12 while (octal != 0) {
13 int digit = octal % 10;
14 decimal += digit * pow(8, i);
15 octal /= 10;
16 i++;
17 }
18
19 printf("Octal %d = Decimal %d\n", original, decimal);
20
21 // Using scanf with format specifier
22 printf("\nVerification using %%o: ");
23 int verify;
24 sscanf("101", "%o", &verify);
25 printf("Octal 101 = Decimal %d\n", verify);
26
27 return 0;
28}
Output

Enter an octal number: 101

Octal 101 = Decimal 65

 

Verification using %o: Octal 101 = Decimal 65

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples