#include<iostream>
using namespace std;
int isPrime(int n)
{
int i,j=1;
for(i=2;i<n;i++)
if(n%i==0)
{
j=0;
break;
}
return j;
}
int isPalindrome(int n)
{
int m=0,u=0;
u=n;
while(n>0)
{
m=m*10+n%10;
n=n/10;
}
if(u==m)
return 1;
else
return 0;
}
int reversible(int n)
{
int m=0,u=0;
u=n;
while(n>0)
{
m=m*10+n%10;
n=n/10;
}
return m;
}
int main()
{
int n;
cout<<"300内的素数为"<<endl;
{
for(n=2;n<300;n++)
if(isPrime(n))
cout<<n<<'\t';
cout<<endl;
}
cout<<"300内的回文数为"<<endl;
{
for(n=2;n<300;n++)
if(isPalindrome(n))
cout<<n<<'\t';
cout<<endl;
}
cout<<"300内的回文素数为"<<endl;
{
for(n=2;n<300;n++)
if(isPalindrome(n)&&isPrime(n))
cout<<n<<'\t';
cout<<endl;
}
cout<<"300内的可逆素数为"<<endl;
{
for(n=2;n<300;n++)
if(isPrime(n)&&isPrime(reversible(n)))
cout<<n<<'\t';
cout<<endl;
}
return 0;
}
---------------------
作者:norxingchen09
来源:CSDN
原文:https://blog.csdn.net/norxingchen09/article/details/51593419
版权声明:本文为博主原创文章,转载请附上博文链接!
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交