-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWIP.cpp
More file actions
74 lines (58 loc) · 1017 Bytes
/
WIP.cpp
File metadata and controls
74 lines (58 loc) · 1017 Bytes
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <cmath>
bool decision(const int &, const int &);
int reverse(int &numb)
{
int lastDigit = 0;
int rev = 0;
while(numb > 0)
{
lastDigit = numb % 10;
rev *= 10 + lastDigit;
numb /= 10;
}
return rev;
}
bool isPrime(const int &numb)
{
if(numb <= 1)
return false;
else
{
for(int i = 2; i <= sqrt(numb); i++)
{
if(numb % i == 0)
return false;
}
}
}
void isTruncatable(int &num)
{
int revNum = reverse(num);
while(isPrime(num) && isPrime(revNum))
{
num = num / 10;
revNum = revNum / 10;
}
decision(num, revNum);
}
bool decision(const int &num, const int &revNum)
{
if(num == 0 && revNum == 0)
{
std::cout << "The number is truncatable prime" << std::endl;
return true;
}
else
{
std::cout << "The number cannot be truncatable prime" << std::endl;
return false;
}
}
int main()
{
int num, numLastDigit, revNumLastDigit = 0;
std::cout << "Enter the number" << std::endl;
std::cin >> num;
isTruncatable(num);
}