题目:回文素数

求不超过1000的回文素数。 

1 #include <stdio.h>
  2 
  3 int main()
  4 {
  5     int i,j,t,k,s;
  6 
  7     printf("Following are palindrome primes not greater than 1000:\n");
  8     for(i = 0;i <= 9;i++)
  9     {
 10         for(j = 0;j <= 9;j++)
 11         {
 12             for(k = 0;k <= 9;k++)
 13             {
 14                 s = i * 100 + j * 10 + k;
 15                 t = k * 100 + j * 10 + i;
 16                 if(i == 0 && j == 0)
 17                 {
 18                     t /= 100;
 19                 }
 20                 else if(i == 0)
 21                 {
 22                     t /= 10;
 23                 }
 24                 if(s > 10 && s == t && a(s))
 25                 {
 26                     printf("%d\t",s);
 27                 }
 28             }
 29         }
 30     }
 31     return 0;
 32 }
 33 

猜你喜欢

转载自blog.csdn.net/weixin_42720729/article/details/81287797
今日推荐