/* Program to print largest prime palindrome with range (1-1000)
Problem - https://www.codeeval.com/open_challenges/3/
*/
#include <iostream>
using namespace std;
int main() {
int num,i,j,digit = 0,rev = 0;
int flag = 0;
for (i = 1000;i >= 2;i--) {
flag = 0,rev = 0;
//check for prime
for ( j =2; j < i /2;j++) {
if ( i % j == 0) {
flag = 1;break;
}
}
if (!flag) {
//if prime check for palindrome
num = i,rev = 0;
while (num > 0) {
digit = num % 10;
rev = rev * 10 + digit;
num /= 10;
}
}
if ( i == rev) {
cout << "Largest Prime Palindrome between (1-1000) = " << i << endl;
break;
}
}
return 0;
}
Output -
Largest Prime Palindrome between (1-1000) = 929
Comments