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.
amisha7396:
please give the answer its urgent
Answers
Answered by
1
Solution in C++ =>
#include <iostream>
#include <math.h>
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;
}
#include <iostream>
#include <math.h>
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;
}
Answered by
0
Answer:
Explanation:
Where the first community technical telecentre was opened
Similar questions
Physics,
6 months ago
Social Sciences,
6 months ago
English,
11 months ago
English,
11 months ago
Computer Science,
1 year ago
Hindi,
1 year ago
Hindi,
1 year ago