-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path85thProgram_PalindromicPrimeuptoARange.cpp
More file actions
50 lines (49 loc) · 1.09 KB
/
Copy path85thProgram_PalindromicPrimeuptoARange.cpp
File metadata and controls
50 lines (49 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
using namespace std;
int main()
{
int range;
cout << "Enter a range:"
<< "\n";
cin >> range;
cout << "Prime Palindromic numbers upto range:" << range << "are:"
<< "\n";
for (int i = 2; i <= range; i++)
{
int s = 0;
int count;
int rev = 0;
int temp = i;
int temp1 = i;
int temp2 = i;
int digit;
while (temp != 0)
{
temp = temp / 10;
s = s + 1;
}
for (int i = 1; i <= s; i++)
{
digit = temp1 % 10;
rev = rev * 10 + digit;
temp1 = temp1 / 10;
}
if (rev == temp2)
{
count = 0;
for (int j = 2; j <= temp2 / 2; j++)
{
if (temp2 % j == 0)
{
count = count + 1;
break;
}
}
if (count == 0)
{
cout << temp2 << "\n";
}
}
}
return 0;
}