// qmakeCpp
#include <iostream>
#include <cstdlib>
using namespace std ;
int main( void ) {
int mark = 0 ;
int n=0 , base = 0 , x=0 , a[100] ;
while( mark != -1 ){
cout << "Please input the number you need to transfer:" ;
cin >> n ;
cout << "Please input the base:" ;
cin >> base ;
while( n ) {
a[ x++ ] = n % base ;
n /= base ;
}
--x ;
while( x >= 0 ){
cout << a[ x-- ] << " " ;
}
x = 0 ; // !
cout << endl ;
cout << "To exit please input -1 , input others otherwise . :" ;
cin >> mark ;
}
cout << "Please pay attention to the blank space in result. " ;
cout << "You may need to deal the result deeply , for example change 10 to a/A etc. when the base is 16." << endl ;
return EXIT_SUCCESS ;
}
本文介绍了一个简单的C++程序,该程序能够将一个十进制数转换为用户指定的任意进制数(2到36)。通过不断除以目标进制并取余数的方式,程序递归地计算出每个位上的数值。为了方便用户多次使用程序,还提供了一个退出选项。
667

被折叠的 条评论
为什么被折叠?



