C Program to convert a decimal to octal number
Program
#include<stdio.h>
#include<math.h>
int octal_decimal(int num)
{
int dec = 0, rem = 0, i = 0;
while(num != 0)
{
rem = num % 10;
num = num / 10;
dec = dec + rem * pow(8, i);
++i;
}
return dec;
}
void main()
{
int num, result;
printf("Enter a octal number:\t");
scanf("%d", &num);
result = octal_decimal(num);
printf("The decimal equivalent is:\t%d\n", result);
}
Output
Enter a octal number: 128
The decimal equivalent is: 88