#include <iostream>
#include <algorithm>
using namespace std;
string func(int n, int k){
string s;
while(n > 0){
if(n % k < 10) s += (n % k) + '0';
else s += (n % k - 10) + 'A';
n /= k;
}
reverse(s.begin(), s.end());
return s;
int main() {
int N;
cin >> N;
int a[3] = {2, 8, 16};
for(auto &i : a)
cout << "Number " << N << " in the notation with a base " << i << " equals to " << func(N, i) << "\n";
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <algorithm>
using namespace std;
string func(int n, int k){
string s;
while(n > 0){
if(n % k < 10) s += (n % k) + '0';
else s += (n % k - 10) + 'A';
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
int main() {
int N;
cin >> N;
int a[3] = {2, 8, 16};
for(auto &i : a)
cout << "Number " << N << " in the notation with a base " << i << " equals to " << func(N, i) << "\n";
}