Convert Octal to Decimal in C


Prev Tutorial Next Tutorial

Convert Octal to Decimal Program in C

In this types of program we takes a Octal number as input and converts it into Decimal number. To convert Octal to Decimal number first accept Octal as a input then convert into equivalent Decimal number

Steps to Convert Octal to Decimal Number

  • Start the decimal result at 0.
  • Remove the most significant octal digit (leftmost) and add it to the result.
  • If all octal digits have been removed, you are done. Stop.
  • Otherwise, multiply the result by 8.
  • Go to step 2.

Convert Octal to Decimal in C

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

void main()
{
 
    long int octal, decimal = 0;
    int i = 0;
    clrscr();
    printf("Please Enter any Octal Number: ");
    scanf("%ld", &octal);
    while (octal != 0)
    {
        decimal =  decimal +(octal % 10)* pow(8, i++);
        octal = octal / 10;
    }
    printf("Equivalent decimal value: %ld",decimal);
 
    getch(); 
}

Output 1

Please Enter any Octal Number: 82
Equivalent Decimal Value is: 66

Output 2

Please Enter any Octal Number: 16
Equivalent Decimal Value is: 14

Prev Tutorial Next Tutorial

Download Projects

Google Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Advertisements