C Program to Convert Binary Number to Octal



In this program we will convert Binary Number into Octal



  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!
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


Join Our Facebook Group


Share this example


Download Android App

download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube