橙子学C语言(3)
//判断回文数,和水仙花数。(回文数12321,32623这样的数)(水仙花是个位立方+十位立方+百位立方=数字本身)void main() {
int a, b, c;
int x, t;
printf("水仙花数是:");
for(x = 100; x <= 999; x++) {
a = x/100; //百位数
b = (x % 100) / 10; //十位数
c = x % 10; //个位数
t = a * a * a + b * b * b + c * c * c;
if(t == x) {
printf("%d,", x);
}
}
} // 回文数
void main() {
int a, b, c, d;
int x;
printf("回文数有:");
for(x = 10000; x <=99999; x++) {
a = x/10000;
b = (x % 10000) / 1000;
c = (x % 100) / 10;
d = x % 10;
if((a == d) && (b == c)) {
printf("%d,", x);
}
}
}
页:
[1]