Conversion of decimal number n and other d number


#include<cstdlib>
#include<iostream>
using namespace std;
#define size 100
int a[size+1],n,d,i=0,j;
main ()
{
    
    
cout<<"Please enter a number(N) base 10:";
cin >> n;
cout << "Please enter a number(d):" << endl;
cin >> d;
do{
    
    
a[++i]=n%d;
n=n/d;
}while(n!=0);
for(j=i;j>=1;j--)
cout<<a[i];
return 0;
}


Algorithm principle:
n=(n/d)*d+n%d
/ is the division operation,% is the remainder operation

Guess you like

Origin blog.csdn.net/qq_51082388/article/details/113105841