Convert Octal to Decimal in C

Advertisements

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

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements