1.

write a program to enter an integer number and check whether it is a pal prime or not.where the number should be a prime number as well as palindrome.

Answer»

n in C++ =>#include #include using namespace std;bool palindrome(int n) { int i,R,s=0; for(i=n;i!=0;i=i/10) { r=i%10; s=s*10+r; } if(s==n) return TRUE; else return false;}bool prime(int n) { int i; if(n==1) return false; else { for(i=2;i<=SQRT(n);i++) { if(n%i==0) return false; } } return true;}int main() { int n; cin>>n; if(palindrome(n)) { if(prime(n)) cout<<"YES"; else cout<<"no"; } else cout<<"no"; return 0;}



Discussion

No Comment Found