#include <stdio.h>
#include <math.h>
int main() {
int octal, decimal = 0, power = 0;
printf("Enter an octal number: ");
scanf("%d", &octal);
while (octal != 0) {
int digit = octal % 10;
decimal += digit * pow(8, power);
octal /= 10;
power++;
}
printf("The decimal equivalent is %d\n", decimal);
return 0;
}
Enter an octal number: 243
The decimal equivalent is 163
octal
number, decimal to store the decimal
equivalent, and power to keep track of the current power
of 8.printf
and scanf
.while
loop to convert each digit of the octal number to decimal. The loop continues until the octal number becomes 0.%
, and then multiply it with 8 raised to the current power of 8 using the pow
function from the math library. We add this value to the decimal
variable.power
variable by 1 to move to the next digit.decimal
variable as the decimal equivalent using printf
.