Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- // Declare and read the value of x
- int x;
- cin >> x;
- // Declare and read the value of y
- int y;
- cin >> y;
- // Declare variable result and save the converted value of y into x number system in it
- string result;
- if (x < 2 || x>16 || y < 1 || y>100)
- {
- cout << "Invalid input data!";
- return 1;
- }
- while (y > 0)
- {
- int ostatuk = y % x;
- char sym;
- if (ostatuk < 10)
- {
- sym = '0' + ostatuk;
- }
- else
- {
- sym = 'A' + ostatuk - 10;
- }
- result = sym + result;
- y /= x;
- }
- // Print result to the console
- cout << result;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement