发布网友 发布时间:2022-10-12 08:45
共2个回答
热心网友 时间:2023-10-20 21:08
#include <stdio.h>
bool IsPalindromeNum(int num) {
char s[10],i = 0,j;
while(num > 0) {
s[i] = num % 10 + '0';
num = num / 10;
i++;
}
s[i] = '\0';
i--;
for(j = 0;j < (i + 1)/2;j++) if(s[j] != s[i - j]) return false;
return true;
}
void Primes(int m,int n) {
int i,j,flag,counter = 0;
if(m % 2 == 0) m++;
for(i = m;i <= n;i += 2) {
flag = 1;
for(j = 2;j*j < i + 1;j++) {
if(i % j == 0) {
flag = 0;
break;
}
}
if(flag && IsPalindromeNum(i)) {
if(counter % 10 == 0) printf("\n");
printf("%6d",i);
counter++;
}
}
printf("\n");
}
int main() {
int m = 100,n = 9999;
printf("%d到%d之间的回文素数有:\n",m,n);
Primes(m,n);
printf("\n");
return 0;
}
热心网友 时间:2023-10-20 21:08
你想问什么?