Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. //Bài tập 9: Viết một hàm chuyển dữ liệu số thập phân sang số nhị phân
  2.  
  3. #include<iostream>
  4. using namespace std;
  5. void handling(int n)
  6. {
  7.     int arr[100];
  8.     int temp, t=0;
  9.     for (int i = 0; i < 100; i++)
  10.     {
  11.         temp = n / 2;
  12.         arr[i] = n % 2;
  13.         n = temp;
  14.         t++;
  15.         if (temp == 0)
  16.         {
  17.             break;
  18.         }
  19.     }
  20.     cout << "Switch to binary number is : ";
  21.     for (int i = t; i >= 0; i--)
  22.     {
  23.         cout << arr[i];
  24.     }
  25.     cout << ";" << endl;
  26. }
  27. int main()
  28. {
  29.     int x;
  30.     cout << "Enter x : ";
  31.     cin >> x;
  32.     handling(x);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement