河北专接本C语言程序第四天
100-99999内的所有回文数
#include <stdio.h>
#define zhimax 99999
#define zhimin 100
int huiwenshupd(int x);
int main() {
int i,sum=0,q=0;
for (i = zhimin; i <= zhimax; i++) {
if ((huiwenshupd(i) == 1)) {
printf("\t%d",i);sum++;
if (q<5) {q++;}else {q = 0;printf("\n");}
}
}
printf("回文数共有 %d 个",sum);
return 0;}
huiwenshupd(int x) {
int rec = 0,sum=0,xx;
xx = x;
while (x != 0) {
rec = x % 10;x /= 10;
sum = sum * 10 + rec;
}
if (xx == sum) {
return 1;
}
else {
return 0;
}
}
参考自C语言每日一练——第6天:回文数_Super辉sir的博客-CSDN博客
#include<stdio.h>
int main() {
int shu = 100, he1 = 0, he2 = 0, he3 = 0;
for (shu = 100; shu <= 99999; shu++) {
if (100 <= shu && shu <= 999) {
if ((shu / 100) == (shu % 10)) {
he1++;
}
else {}
}
else if (1000 <= shu && shu <= 9999) {
if ((shu / 1000) == (shu % 10) &&((shu/100)%10)==((shu%100)/10)) {
he2++;
}
else {}
}
else if (10000 <= shu && shu <= 99999) {
if ((shu / 10000) == (shu % 10) && ((shu / 1000) % 10) == ((shu % 100) / 10)) {
he3++;
}
else {}
}
}
printf("%d %d %d %d", he1 + he2 + he3, he1, he2, he3);
}