SabirSazzad

Decimal to Binary

Feb 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int binary_decimal(int n);
  4. int decimal_binary(int n);
  5. int main()
  6. {
  7.     int n,number;
  8.     scanf("%d", &n);
  9.     number = decimal_binary(n);
  10.     printf("%d",number);
  11.     return 0;
  12. }
  13.  
  14. int decimal_binary(int n)  /* Function to convert decimal to binary.*/
  15. {
  16.     int rem, i=1, binary=0;
  17.     while (n!=0)
  18.     {
  19.         rem=n%2;
  20.         n/=2;
  21.         binary+=rem*i;
  22.         i*=10;
  23.     }
  24.     return binary;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment