-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler7.cpp
More file actions
47 lines (36 loc) · 700 Bytes
/
Copy patheuler7.cpp
File metadata and controls
47 lines (36 loc) · 700 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
//
// Created by Henry Glover on 8/21/23.
//
/*
* By Listing the first six prime numbers
* 2,3,5,7,11,13
*
* we can see that the 6th prime is 13
*
* what is the 10001 prime number?
*
*/
#include <iostream>
bool isPrime (int num) ;
int main () {
int num = 2 ;
int count = 0 ;
while (count != 10001) {
if (isPrime(num)) {
count++;
}
num++;
}
std::cout << " The 10001st prime number is : " << num -1 << std::endl;
}
bool isPrime (int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i <= std::sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}