This is a C program to convert octal number to decimal.
This program takes a octal number as input and converts it into decimal number.
1. 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;
}
1. Take the octal number as input and store it in the variable octal.
2. Initialize the variables decimal and i to zero.
3. Obtain the remainder and quotient of the octal number. Multiply the remainder by powers of 8 using function pow(8, i++), add this value to the variable decimal and store it in the variable decimal.
4. Override the variable octal with quotient.
5. Repeat the steps 3 and 4 with the quotient obtained until the quotient becomes zero.
6. Print the variable decimal as output.
Output: Enter any octal number: 67 Equivalent decimal value: 55
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice Computer Science MCQs
- Practice BCA MCQs
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Apply for C Internship