C Program to Convert Octal Number to Decimal



The octal numeral system is the base-8 number system, and uses the digits 0 to 7.



  1. //C program to convert octal to decimal
  2. #include <stdio.h>
  3. #include <math.h>
  4. long long convertOctalToDecimal(int octnum);
  5. int main()
  6. {
  7. int octnum;
  8. printf("Enter an octal number: ");
  9. scanf("%d", &octnum);
  10. printf("%d in octal = %d in decimal", octnum, convertOctalToDecimal(octnum));
  11. return 0;
  12. }
  13. long long convertOctalToDecimal(int octnum)
  14. {
  15. int decinum = 0, i = 0;
  16. while(octnum != 0)
  17. {
  18. decinum += (octnum%10) * pow(8,i);
  19. ++i;
  20. octnum/=10;
  21. }
  22. i = 1;
  23. return decinum;
  24. }

Output


Output!