Advertisement
Shailrshah

Decimal to Binary Conversion

May 27th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int convert(int n)
  4. {
  5.     static long int bin;
  6.     static int j;
  7.     int r;
  8.     if(n)
  9.     {
  10.         r = n%2;
  11.         bin += r*pow(10,j++);
  12.         convert(n/2);
  13.     }
  14.     return bin;
  15. }
  16. int main()
  17. {
  18.     int decimal;
  19.     printf("Enter the decimal: ");
  20.     scanf("%d",&decimal);
  21.     printf("The binary form is %ld",convert(decimal));
  22.     fflush(stdin);
  23.     getchar();
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement