Advertisement
ppupil2

C progress 1

Feb 24th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. int main(){
  6.     int x, c, bi[40];
  7.     printf("Convert Decimal to Binary program\n");
  8.     while (1)
  9.     {
  10.         printf("      Enter a positive integer number: ");
  11.         fflush(stdin);
  12.         scanf("%d",&x);
  13.         c = 0;
  14.         while (x>0) {
  15.             bi[c] = x%2;
  16.             x /= 2;
  17.             c++;
  18.         }
  19.         printf("      Binary number: : ");
  20.         for (int i = (c-1); i>0; i--) {
  21.             printf("%d",bi[i]);
  22.         }
  23.         printf("\nPress any key to do another conversion.\n\n");
  24.         getch();
  25.     }
  26.     return(0); 
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement