• Source
    1. #include<stdio.h>
    2. #include<math.h>
    3. main()
    4. {
    5. int oct_num,oct,dec_num,dec,remainder,i,n;
    6. printf("***************Welcome to Converter***************");
    7. printf("\n\n\n1.Octal to Decimal\n\n2.Decimal to Octal\n\n Enter Your choice : ");
    8. scanf("%d",&n);
    9. switch(n)
    10. {
    11. case 1:
    12. printf("\nPlease, Enter the Octal number : ");
    13. scanf("%d",&oct_num);
    14. oct=oct_num;
    15. i=0;
    16. dec=0;
    17. while(oct_num!=0)
    18. {
    19. remainder=oct_num%10;
    20. dec=dec+remainder*pow(8,i);
    21. i++;
    22. oct_num=oct_num/10;
    23. }
    24. printf("\nThe decimal of %d is : %d",oct,dec);
    25. break;
    26. case 2:
    27. printf("\nPlease, Enter the Decimal number : ");
    28. scanf("%d",&dec_num);
    29. dec=dec_num;
    30. i=1;
    31. oct=0;
    32. while(dec_num!=0)
    33. {
    34. remainder=dec_num%8;
    35. dec_num=dec_num/8;
    36. oct=oct+remainder*i;
    37. i=i*10;
    38. }
    39. printf("\nThe octal of %d is : %d",dec,oct);
    40. break;
    41. default:
    42. printf("\n SORRY !!! You have Entered a wrong choice.");
    43. break;
    44. }
    45. return 0;
    46. }