# Convert Octal To Decimal Number C Program

## C Program To Convert Octal To Decimal Number

Learn How To Convert Octal To Decimal Number in C Programming Language. This C code for Octal Number to Decimal Conversion makes use of **pow()** function, **While** loop and** For** loop.

#### Octal Number

An Octal Number has a base 8 and includes the following digits: **0 1 2 3 4 5 6 7**

#### Decimal Number

A Decimal Number has a base 10 and includes digits the following digits: **0 1 2 3 4 5 6 7 8 9**

#### Method 1: C Program To Convert Octal To Decimal Value using While Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<stdio.h> #include<math.h> int main() { int decimal_number = 0, remainder, octal_number; int count = 0; printf("Enter an Octal Number:\t"); scanf("%d", &octal_number); while(octal_number > 0) { remainder = octal_number % 10; decimal_number = decimal_number + remainder * pow(8, count); octal_number = octal_number / 10; count++; } printf("\nDecimal Equivalent:\t%d\n", decimal_number); return 0; } |

#### Method 2: C Program For Octal Number To Decimal Conversion using For Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<stdio.h> #include<math.h> int main() { int decimal_number = 0, remainder, octal_number; int count; printf("Enter an Octal Number:\t"); scanf("%d", &octal_number); for(count = 0; octal_number > 0; count++) { remainder = octal_number % 10; decimal_number = decimal_number + remainder * pow(8, count); octal_number = octal_number / 10; } printf("\nDecimal Equivalent:\t%d\n", decimal_number); return 0; } |

#### Method 3: C Program For Octal To Decimal Conversion using Functions

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<stdio.h> #include<math.h> int octal_to_decimal(int x) { int decimal_number, remainder, count = 0; while(x > 0) { remainder = x % 10; decimal_number = decimal_number + remainder * pow(8, count); x = x / 10; count++; } return decimal_number; } int main() { int octal_number, result; printf("Enter an Octal Number:\t"); scanf("%d", &octal_number); result = octal_to_decimal(octal_number); printf("\nDecimal Equivalent:\t%d\n", result); return 0; } |

#### Output

If you have any compilation error or doubts in this C Program For Octal Value to Decimal Number Conversion, let us know about it in the Comment Section below.

What is the need of the Modulus Operator here? Can you please explain its working?

The Mod Operator is used to extract the last digit of the number of the given number. This statement does it: rem = number%10, which you can manipulate later as done in the above code.

These codes are just so easy to understand. Thanks a lot.

Finally I understood how to convert octal numbers into decimal number in c programming. Thanks.