-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 7.cpp
More file actions
36 lines (34 loc) · 766 Bytes
/
Copy pathProblem 7.cpp
File metadata and controls
36 lines (34 loc) · 766 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
#include <iostream>
/*
Indem wir die ersten sechs Primzahlen auflisten: 2, 3, 5, 7, 11 und 13, können wir sehen,
dass die 6. Primzahl 13 ist.
Was ist die 10 001. Primzahl?
*/
bool isPrime(size_t zahl){
if(zahl < 2){
return false;
}
for(size_t i{2}; i<zahl; i++){
if(zahl%i == 0){
return false;
}
}
return true;
}
int main(){
size_t primzahl_an_stelle{10'001};
size_t tmp_primzahlen_stelle{0};
size_t tmp{0};
size_t hoechste_primzahl{0};
while(tmp_primzahlen_stelle != primzahl_an_stelle){
if(isPrime(tmp)){
if(tmp > hoechste_primzahl){
hoechste_primzahl = tmp;
}
tmp_primzahlen_stelle++;
}
tmp++;
}
std::cout << "Die Primzahl an der Stelle " << tmp_primzahlen_stelle << " ist " << hoechste_primzahl << '\n';
return 0;
}