#include <stdio.h>
#include <math.h>
long long convertOctalToDecimal(int octalNumber);
int main()
{
int octalNumber;
printf("Enter an octal number: ");
scanf("%d", &octalNumber);
printf("%d in octal = %lld in decimal", octalNumber, convertOctalToDecimal(octalNumber));
return 0;
}
long long convertOctalToDecimal(int octalNumber)
{
int decimalNumber = 0, i = 0;
while(octalNumber != 0)
{
decimalNumber += (octalNumber%10) * pow(8,i);
++i;
octalNumber/=10;
}
i = 1;
return decimalNumber;
}
Output
Enter an octal number: 116
116 in octal = 78 in decimal
No comments:
Post a Comment