Advertisement
nguyenhappy92

Đổi một số hệ 10 sang hệ 2.

Oct 27th, 2015
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. // Viet chuong trinh doi 1 so nguyen duong 10 sang he 2
  2. // Khai bao thu vien chuong trinh neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8.  
  9. int x;
  10. scanf("%d",&x);
  11. int a[100],t,i,k;
  12. k=0;
  13. while(x>0)
  14. {
  15. k++;
  16. t=x%2;
  17. a[k]=t;
  18. x=x/2;
  19. }
  20. for(i=k;i>0;i--)
  21. {
  22. printf("%d ",a[i]);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement