#include <iostream>
using namespace std;
int main() {
int num;
cout << "请输入一个最多四位的正整数:";
cin >> num;
if (num < 1 || num > 9999) {
cout << "输入不合法!" << endl;
return 0;
}
if (num == 1) {
cout << "颠倒后是1" << endl;
return 0;
}
int reversedNum = 0;
while (num > 0) {
reversedNum = reversedNum * 10 + num % 10;
num /= 10;
}
cout << "颠倒后是:" << reversedNum << endl;
return 0;
}
using namespace std;
int main() {
int num;
cout << "请输入一个最多四位的正整数:";
cin >> num;
if (num < 1 || num > 9999) {
cout << "输入不合法!" << endl;
return 0;
}
if (num == 1) {
cout << "颠倒后是1" << endl;
return 0;
}
int reversedNum = 0;
while (num > 0) {
reversedNum = reversedNum * 10 + num % 10;
num /= 10;
}
cout << "颠倒后是:" << reversedNum << endl;
return 0;
}