PCLP2/lab07/02.cpp

23 lines
340 B
C++
Raw Permalink Normal View History

2020-05-01 14:58:05 +00:00
#include <iostream>
using namespace std;
int convert(int number, int base){
if(number == 0 || base == 10){
return number;
}
return (number%base) + 10 * convert(number / base, base);
}
int main(){
int n, base;
cout<<"Number: ";
cin>>n;
cout<<"Target base: ";
cin>>base;
cout<<"Result: "<<convert(n, base)<<endl;
return 0;
}