Write a C program to read Octal number from user and convert to Decimal number system. How to convert from Octal number system to Decimal number system in C.

Input Octal number: (172)

Output Decimal number: (122)

Happy coding ;)

**Example:**Input Octal number: (172)

_{8}Output Decimal number: (122)

_{10}### Required knowledge:

Basic C programming, For loop#### Octal number system:

Octal number system is a base 8 number system. Octal number system uses 8 symbols to represent all its numbers i.e. 0 1 2 3 4 5 6 7#### Decimal number system:

Decimal number system is a base 10 number system. Decimal number system uses 10 symbols to represent all its numbers i.e. 0 1 2 3 4 5 6 7 8 9### Algorithm to convert from Octal to Decimal:

Algorithm Conversion Octal to Binarybegin:read(OCTAL);DECIMAL← 0;REM← 0;PLACE← 0;While(OCTAL!=0)begin:REM←OCTAL% 10;DECIMAL←DECIMAL+ (8^{PLACE}*REM);OCTAL←OCTAL/ 10;PLACE←PLACE+ 1;end;write('Decimal ='DECIMAL);end;

### Program:

/** * C program to convert Octal number system to Decimal number system */ #include <stdio.h> #include <math.h> int main() { long long octal, tempOctal, decimal; int rem, place; /* * Reads octal number from user */ printf("Enter any octal number: "); scanf("%lld", &octal); tempOctal = octal; decimal = 0; place = 0; /* * Finds decimal of octal number */ while(tempOctal!=0) { rem = tempOctal % 10; decimal += pow(8, place) * rem; tempOctal /= 10; place++; } printf("\nOctal number = %lld\n", octal); printf("Decimal number = %lld", decimal); return 0; }

Output

Enter any octal number: 172

Octal number = 172

Decimal number = 122

Octal number = 172

Decimal number = 122

Happy coding ;)

### You may also like

- Loop programming exercises and solutions in C.
- C program to find one's complement of a binary number.
- C program to find two's complement of a binary number.
- C program to convert Binary to Octal number system.
- C program to convert Binary to Decimal number system.
- C program to convert Binary to Hexadecimal number system.
- C program to convert Octal to Binary number system.
- C program to convert Octal to Hexadecimal number system.
- C program to convert Decimal to Binary number system.
- C program to convert Decimal to Octal number system.
- C program to convert Decimal to Hexadecimal number system.
- C program to convert Hexadecimal to Binary number system.
- C program to convert Hexadecimal to Octal number system.
- C program to convert Hexadecimal to Decimal number system.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).