您的位置:首页 > 编程语言 > C语言/C++

C++实现数字反转

2019-03-10 15:02 162 查看

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;
}

调试结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: