palindrome prime
this is a program for finding a smallest number that is prime and also palindrome
you have to enter a number and it finds the number which is greater than and equal to this number and smallest number that is prime and palindrome both.
#include<stdio.h>
#include<math.h>
int primecheck(int);
int palindromecheck(int);
int main()
{
int i,n,m,p;
scanf("%d",&n);
for(i=n;;i++)
{
m=palindromecheck(i);
if(m)
{
p=primecheck(i);
if(p)
{
printf("%d",i) ;
break;
}
}
}
system("pause");
return 0;
}
int primecheck(int n)
{
int i;
if(n==0||n==1)
return 0;
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int palindromecheck(int n)
{
int temp,rev=0,x;
temp=n;
while(temp)
{
x=temp%10;
rev=rev*10+x;
temp=temp/10;
}
if(rev==n)
return 1;
else
return 0;
}
No comments:
Post a Comment