1.实现输入一串数字后倒序输出:
#include <iostream>
#include <climits>
#include <cmath>
using namespace std;
int main()
{
int num;
int temp = 0;
cin >> num; //键盘输入
while(true){
if(num <= 0){ //全部取完之后循环终止
break;
}
temp = temp*10 + (num % 10) ; //num % 10获得个位数
num = num /10 ; //将数字小数点往前一位
}
cout << temp << endl;
return 0;
}
- 运行结果: