Advertisement
Waliul

3. Convert octal number to decimal

Sep 9th, 2021
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int octal, decimal, i, j;
  6.     printf("Enter the octal number : ");
  7.     scanf("%d", &octal);
  8.     decimal = 0;
  9.     i = 0;
  10.  
  11.     while(octal != 0)
  12.     {
  13.         j = octal % 10;
  14.         decimal += j * pow(8, i);
  15.         octal /= 10;
  16.         i++;
  17.     }
  18.  
  19.     printf("\nThe decimal is : %d\n", decimal);
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement