用c语言代码for语句用for语句输出100-999中所有个位数与百位数相加为9的数
#include <stdio.h>
int main() {
int i;
for (i = 100; i <= 999; i++) {
int units = i % 10; // 取出个位数
int hundreds = i / 100; // 取出百位数
if (units + hundreds == 9) { // 判断个位数与百位数之和是否为9
printf("%d\n", i); // 输出符合条件的数
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/e2CG 著作权归作者所有。请勿转载和采集!