write a C program to convert an octal number to its equivalent decimal number
Answers
Answered by
2
C Program to Convert Octal to Decimal
This is a C program to convert octal number to decimal.
Problem DescriptionThis program takes a octal number as input and converts it into decimal number.
Problem Solution1. Take a octal number as input.
2. Multiply each digits of the octal number starting from the last with the powers of 8 respectively.
3. Add all the multiplied digits.
4. The total sum gives the decimal number.
Here is source code of the C program to Convert Octal to Decimal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C Program to Convert Octal to Decimal */#include <stdio.h>#include <math.h> int main(){ long int octal, decimal = 0; int i = 0; printf("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); return 0;}Similar questions