【2070】数字对调
【题目描述】
输入一个三位数,要求把这个数的百位数与个位数对调,输出对调后的数。
【输入】
三位数。
【输出】
如题述结果。
【输入样例】
123
【输出样例】
321
【程序分析】
本题主要考察如何获取到一个数的百位,十位,个位,这个技巧要掌握,用整除和取余运算相配合
num / 100
得到百位数(num / 10) % 10
得到十位数num % 10
得到个位数
【程序实现】
#include <stdio.h>int main() {int num;scanf("%d", &num); // 读取三位数int hundreds = num / 100; // 获取百位数int tens = (num / 10) % 10; // 获取十位数int units = num % 10; // 获取个位数// 重新组合:个位数变百位,十位数不变,百位数变个位int result = units * 100 + tens * 10 + hundreds;printf("%d\n", result);return 0;
}