ibrahim_065

4.Write a program to convert a decimal number to its binary equivalent.

Aug 13th, 2020 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. // Write a program to convert a decimal number to its binary equivalent.
  2. #include<stdio.h>
  3. int main()
  4. {
  5.     int n = 1000005, ar[50], count = 0;
  6.     while(n != 0)
  7.     {
  8.         ar[count] = n % 2;
  9.         count++;
  10.         n /= 2;
  11.     }
  12.     for (int i = count-1; i >= 0; --i)
  13.     {
  14.         printf("%d", ar[i]);
  15.     }
  16.     return 0;
  17. }
Add Comment
Please, Sign In to add comment