# C program to convertOctal todecimal number

## C program to convert Octal to decimal number

This page has a C program to convert Octal to decimal number. We can easily write the C program to convert a given mixed Octal number into decimal number equivalent. To convert the Octal number, we should multiply the each digits  present in the Octal number with their weights and add them (products) together to form the decimal equivalent. For Example: Let us find the decimal equivalent of Octal number (746.124)8 using the below given converter program. The Given Octal number: (746.124). The Decimal equivalent is calculated as:  7*8*8 + 4*8 + 6*1 + 1*1/8 + 2*1/(8*8) + 4*1/(8*8*8) = 43.71875  Decimal equivalent of (746.124) is (486.1640625)  The below given C program is used to convert a given mixed Octal number into its equivalent decimal number. Kindly check out the program to convert a Octal to decimal number.

### Octal to decimal conversion Program

#include <stdio.h>
#include <math.h>
int main(){
unsigned intpart=0;
int a=0,j=0,m,n=0,q=1,h=-1,remr;
long float dn;
char g1[80], p2[80]={'\0'};
clrscr();
printf("Give an Octal number : ");
gets(g1);
for (a = 0; g1[a] != '\0'; a++){
q++;
}
for(m=0;m<q-1;m++){
if(g1[m] == '.')
break;
}
for(a=m+1;a<=q-1;a++){
p2[n]=g1[a];
n++;
j++;
}
n=0;
printf("\n\n The given Octal number is : %s \n\n", g1);
for(a=m-1;a>=0;a--){
remr = g1[n]-'0';
if((remr>=0)&&(remr<=7)){
intpart = intpart + remr * pow(8,a);
n++;
}
else {
printf("\n\n Please Enter Valid Octal Number !!!");
getch();
exit();
}
}
for(a=1;a<=j-1;a++){
remr = p2[a-1]-'0';
if((remr>=0)&&(remr<=7)){
dn = dn + (float)remr * pow(8,h);
--h;
}
else {
printf("\n\n Please Enter Valid Octal Number !!!");
getch();
exit();
}
}
printf("\n\n The Decimal number is : %lf", intpart+dn);
getch();
return(0);
}

Sample Output:

Give an Octal number :  746.124
The Decimal number is :   486.1640625

Give an Octal number :  34652.1674
The Decimal number is :   14762.233398

Give an Octal number :  45354424.245134
The Decimal number is :   9820436.32262

### Other Popular Converter Calculators

I have included a set of online converters in this page. Kindly checkout all the converters and find the differences between the converters and the converters available already. Binary to Decimal converter, Octal to Decimal converter, Hexadecimal to Decimal converter, Decimal to Binary converter, Decimal to Octal converter, Decimal to Hexadecimal converter, Binary to Hexadecimal converter, Binary to Octal converter, Hexadecimal to Binary converter, and Octal to Binary converter,