C++实现数字反转

1.现将数字n对10取余
2.再将数字n对10取整
3.循环第一,二步即可

#include <iostream>
using namespace std;
int main(void)
{
 int n,right_digit;
 cout<<"Enter the number:";
 cin>>n;
 cout<<"The number in reverse order is ";
 do
 {
  right_digit = n%10;
  cout <<right_digit;
  n/=10;
 }
 while(n!=0);
 cout<<endl;
}

调试结果:

猜你喜欢

转载自blog.csdn.net/qq_42153903/article/details/88378657