Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Input(int &number)
- {
- //Điều kiện nhập số nguyên dương > 0
- do
- {
- cout << "\nEnter number : ";
- cin >> number;
- if (number < 0)
- cout << "Xin moi ban nhap lai : " << endl;
- } while (number < 0);
- }
- void DecimalToHexadecimal(int number)
- {
- char hexadecimal[100];
- int i = 0,surplus;
- while (number > 0)
- {
- surplus = number % 16;
- if (surplus < 10)
- {
- //Xem bản ASCII số 0 bắt đầu từ 48
- surplus += 48;
- }
- else
- {
- //Xem bản ASCII chữ A bắt đầu từ 55
- surplus += 55;
- }
- hexadecimal[i] = surplus;
- number /= 16;
- i++;
- }
- cout << "Decimal to Hexadecimal: ";
- for (int j = i - 1; j >= 0; j--)
- {
- cout << hexadecimal[j];
- }
- cout << endl;
- }
- int main()
- {
- int number;
- Input(number);
- DecimalToHexadecimal(number);
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement