Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- #include<iostream>
- using namespace std;
- void handling(int n)
- {
- int arr[100];
- int temp, t=0;
- for (int i = 0; i < 100; i++)
- {
- temp = n / 2;
- arr[i] = n % 2;
- n = temp;
- t++;
- if (temp == 0)
- {
- break;
- }
- }
- cout << "Switch to binary number is : ";
- for (int i = t; i >= 0; i--)
- {
- cout << arr[i];
- }
- cout << ";" << endl;
- }
- int main()
- {
- int x;
- cout << "Enter x : ";
- cin >> x;
- handling(x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement