信息学奥赛一本通C++题解 · 2024年2月15日 52 0

2070:【例2.13】数字对调

【题目描述】

输入一个三位数,要求把这个数的百位数与个位数对调,输出对调后的数。

【输入】

三位数。

【输出】

如题述结果。

【题解代码】

#include <iostream> 
using namespace std;
int main()
{
	int s;
	cin >> s;

	int a = s % 10;  //个位
	int b = s / 10 % 10;  //十位
	int c = s / 100;  //百位

	cout << a * 100 + b * 10 + c;

    return 0;
}