-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprimeSubString.cpp
More file actions
62 lines (44 loc) · 762 Bytes
/
primeSubString.cpp
File metadata and controls
62 lines (44 loc) · 762 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
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
int isPrime(int num){
int flag=1;
if(num!=1)
{
for(int i = 2; i <= num / 2; i++) {
if(num % i == 0) {
flag = 0;
break;
}
}
return flag;
}
else
{
return 0;
}
}
int main()
{
string num;
cin>>num;
int count=0;
int hold;
for(int i=0;i<(num).length();i++)
{
hold = int(num[i]-'0');
for(int j=i+1;j<(num).length();j++)
{
//hold = (hold*10)+int(num[j]-'0');
cout<<"Hold "<<hold<<endl;
if(isPrime(hold))
{
count++;
cout<<hold<<endl;
}
hold = (hold*10)+int(num[j]-'0');
}
}
cout<<" Count "<<count<<endl;
}