Написать программу на языке C++. Перевести с помощью рекурсивной функции conv (n, p) за- данное натуральное число n в p-ичную систему счисления (2 ≤ р ≤ 9).
cout << "Enter a natural number: "; cin >> n; cout << "Enter the base for conversion (2-9): "; cin >> p; if(p < 2 || p > 9) { cout << "Invalid base! Please enter a base between 2 and 9." << endl; return 1; } cout << n << " in base " << p << " is: "; conv(n, p); cout << endl; return 0;
using namespace std;
void conv(int n, int p) {
conv(n / p, p);if(n == 0) {
return;
}
cout << n % p;
}
int main() {
cout << "Enter a natural number: ";int n, p;
cin >> n;
cout << "Enter the base for conversion (2-9): ";
cin >> p;
if(p < 2 || p > 9) {
cout << "Invalid base! Please enter a base between 2 and 9." << endl;
return 1;
}
cout << n << " in base " << p << " is: ";
conv(n, p);
cout << endl;
return 0;
}