## Octal to decimal conversion using C

In this article we will see some C program to convert octal to decimal in C. You can try this program using different way.

Octal number is 8 based number where we use 0, 1, 2, 3, 4, 5, 6 and 7 to write any number. And the decimal is the most common number which we use in our daily life. Here we use 0 to 9 for writing any number. In this C programming guide we will make some program which will convert our given octal number to equivalent decimal number.

You can learn mathematically conversion from octal to decimal from this octal to decimal conversion guide by World Tech Journal.

## C program to convert octal to decimal

``````// convert octal to decimal in c

#include <stdio.h>
#include <math.h>

int main(){
int oct, dec = 0, t = 0;

printf("Enter the octal number to convert : ");
scanf("%d", &oct);

while(oct != 0){
dec = dec + (oct % 10) * pow(8, t);
oct /= 10;
t++;
}

printf("\nEquivalent decimal is = %ld\n", dec);

return 0;
}``````

### Output of this octal to decimal conversion program ## Octal to decimal conversion using function in C

``````// octal to decimal conversion program using function

#include <stdio.h>
#include <math.h>

int convert_oct_to_d(int oct);

int main(){
int octal;

printf("Enter octal number here : ");
scanf("%d", &octal);

printf("\nDecimal equivalence is = %d\n", convert_oct_to_d(octal));

return 0;
}

int convert_oct_to_d(int oct){
int deci = 0, t = 0;

while(oct != 0){
deci = deci + (oct % 10) * pow(8, t);
t++;
oct = oct / 10;
}

return deci;
}``````

### Program output

``````Enter octal number here : 225

Decimal equivalence is = 149``````

Previous pageDecimal to octal

Next pageBinary to octal

Recommended for you: