**Write a C program to enter an octal number and convert octal number to decimal number system.**

Wap in C to convert octal number to decimal number.

How to convert octal number to binary number.

Wap in C to convert octal number to decimal number.

How to convert octal number to binary number.

#### Required Knowledge

**Octal number system** is a base 8 number system using digits 0 and 7 whereas **Decimal number system** is base 10 number system and using digits from 0 to 9. Given an octal number as input from user convert it to decimal number.

##### For Example

2015 in**Octal**is equivalent to 1037 in

**Decimal**number system.

**Algorithm to convert Octal to Decimal number**

- We multiply each octal digit with 8
^{i}and add them, where i is the position of the octal digit(starting from 0) from right side. Least significant digit is at position 0.

Decimal number = 2*8

^{3}+ 0*8

^{2}+ 1*8

^{1}+ 5*8

^{0}= 1024 + 0 + 8 + 5 = 1037

## C program to convert a octal number to decimal number

#include <stdio.h> #include <math.h> int main() { long octalNumber, decimalNumber=0; int position=0, digit; printf("Enter an Octal Number\n"); scanf("%ld", &octalNumber); /* Converting octal number to decimal number */ while(octalNumber!=0) { /* get the least significant digit of octal number */ digit = octalNumber%10; decimalNumber += digit*pow(8, position); position++; octalNumber /= 10; } printf("Decimal Number : %ld", decimalNumber); return 0; }Output

Enter an Octal Number 2015 Decimal Number : 1037

Enter an Octal Number 1234 Decimal Number : 668