p07.cpp
971 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
/*
10001st prime
Problem 7
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
by: dbk
*/
#include <stdio.h>
#define SIZE_ARRAY 10001
int main(int argc, char const *argv[])
{
int *ptrPrime;
int numerador = 1;
int denominador = 2;
int arrayPrime[SIZE_ARRAY] = { 0 };
int counter = 0;
int tmpCounter = 0;
bool flgBuscar = true;
do
{
flgBuscar = true;
numerador = 1;
ptrPrime = arrayPrime;
do
{
while(*ptrPrime != 0 && flgBuscar)
{
numerador = *ptrPrime;
flgBuscar = !(denominador % *ptrPrime++ == 0);
}
if( denominador % numerador == 0 && denominador == numerador )
{
*ptrPrime = denominador;
flgBuscar = false;
counter++;
}
else numerador++;
}while(flgBuscar);
denominador++;
} while (arrayPrime[SIZE_ARRAY-1] == 0);
printf("El primo #%d es:\t%d\n", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]);
return 0;
}