Blame view
07 - Primeros 10001 primos/p07.cpp
915 Bytes
5ec02016e p07: Resuelto, bu... |
1 2 3 4 5 6 7 8 9 10 11 |
/* 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> |
382602797 p07: Reduccion co... |
12 |
#define SIZE_ARRAY 10001 |
5ec02016e p07: Resuelto, bu... |
13 14 15 16 17 18 19 20 |
int main(int argc, char const *argv[]) { int *ptrPrime; int numerador = 1; int denominador = 2; int arrayPrime[SIZE_ARRAY] = { 0 }; |
382602797 p07: Reduccion co... |
21 |
bool flgBuscar = true; |
5ec02016e p07: Resuelto, bu... |
22 23 24 |
do { |
382602797 p07: Reduccion co... |
25 |
flgBuscar = true; |
5ec02016e p07: Resuelto, bu... |
26 27 28 29 30 |
numerador = 1; ptrPrime = arrayPrime; do { |
382602797 p07: Reduccion co... |
31 |
while(*ptrPrime != 0 && flgBuscar) |
5ec02016e p07: Resuelto, bu... |
32 33 |
{ numerador = *ptrPrime; |
382602797 p07: Reduccion co... |
34 |
flgBuscar = !(denominador % *ptrPrime++ == 0); |
5ec02016e p07: Resuelto, bu... |
35 36 |
} |
382602797 p07: Reduccion co... |
37 |
if( denominador % numerador == 0 && denominador == numerador ) |
5ec02016e p07: Resuelto, bu... |
38 39 |
{ *ptrPrime = denominador; |
382602797 p07: Reduccion co... |
40 |
flgBuscar = false; |
5ec02016e p07: Resuelto, bu... |
41 |
} |
382602797 p07: Reduccion co... |
42 43 44 |
else numerador++; }while(flgBuscar); |
5ec02016e p07: Resuelto, bu... |
45 |
|
5ec02016e p07: Resuelto, bu... |
46 |
denominador++; |
9514fc1eb p07: Fix numeros ... |
47 |
} while (arrayPrime[SIZE_ARRAY-1] == 0); |
5ec02016e p07: Resuelto, bu... |
48 |
|
5ec02016e p07: Resuelto, bu... |
49 50 51 52 53 |
printf("El primo #%d es:\t%d ", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]); return 0; } |