每次取个位数的加上去就行了。 #include<iostream> using namespace std; int main() { int n; cin>>n; int res=0; while(n) { res=res*10+n%10; n=n/10; } cout<<res; }