Advertisement
ppupil2

bkict 1

Feb 24th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <conio.h>
  5.  
  6. long int binary(int a); //chuyen decimal sang binary
  7. int main(){
  8. int x; long int bi;
  9. printf("Convert Decimal to Binary program\n");
  10. while (1)
  11. {
  12. printf(" Enter a positive integer number: ");
  13. fflush(stdin);
  14. scanf("%d",&x);
  15. bi = binary(x);
  16. printf(" Binary number: : %ld\n",bi);
  17. printf("Press any key to do another conversion.\n\n");
  18. getch();
  19. }
  20. return(0);
  21. }
  22.  
  23. long int binary(int a){
  24. long int bi=0,x=1; int b;
  25. while (a>0){
  26. b= a%2;
  27. bi+= b*x;
  28. x*= 10;
  29. a/=2;
  30. }
  31. return(bi);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement