Advertisement
Guest User

Base Converting

a guest
Mar 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include<stdio.h> //program to convert base
  2. main()
  3. {
  4.     char digits[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  5.     int store[64];
  6.     int i=0,base,n,no;
  7.     printf("Enter your number: ");
  8.     scanf("%d",&n);
  9.     printf("Enter your base: ");
  10.     scanf("%d",&base);
  11.     do
  12.     {
  13.         store[i]=n%base;
  14.         i++;
  15.         n/=base;
  16.     } while (n);
  17. //the problem is everytime i becomes "-1", when it should have become "i-1"
  18.     for(--i;i>=0;i--);
  19.     {
  20.         printf("%c",digits[store[i]]);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement