C program to convert Octal to decimal 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,

About Er. T.Tharesh Kumar

I am a Professor and Head of Department of Computer Science in an Arts and Science College. I have designed this website to provide solved example programs of different categories for all the school and college going students to learn C language deeply, and to practice Interview based Multiple Choice (Objective Type) questions and answers.

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share