Commit 5ec02016e9fe9a71399188dc15a9f9602dcf8a31

Authored by Francisco Javier Coutiño
1 parent fa2c5b27d6
Exists in master

p07: Resuelto, bug calculando primos pares.

07 - Primeros 10001 primos/core
No preview for this file type
07 - Primeros 10001 primos/p07
No preview for this file type
07 - Primeros 10001 primos/p07.cpp
File was created 1 /*
2 10001st prime
3 Problem 7
4 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
5
6 What is the 10 001st prime number?
7
8 by: dbk
9 */
10
11 #include <stdio.h>
12
13 #define SIZE_ARRAY 10001
14
15 int main(int argc, char const *argv[])
16 {
17
18 int *ptrPrime;
19 int numerador = 1;
20 int denominador = 2;
21 int arrayPrime[SIZE_ARRAY] = { 0 };
22
23 bool flgEnd = false;
24
25 do
26 {
27
28 flgEnd = false;
29 numerador = 1;
30 ptrPrime = arrayPrime;
31
32 do
33 {
34
35 while(*ptrPrime != 0)
36 {
37 numerador = *ptrPrime;
38 if (denominador % *ptrPrime++ == 0)
39 {
40 flgEnd = true;
41 break;
42 }
43
44 }
45
46 if( denominador % numerador == 0 && denominador == numerador)
47 {
48 *ptrPrime = denominador;
49 flgEnd = true;
50 }
51
52 numerador++;
53 }while(!flgEnd);
54 denominador++;
55
56 } while (arrayPrime[SIZE_ARRAY] == 0);
57
58 for (int i = 0; i < SIZE_ARRAY; ++i)
59 {
60 printf("%d\t-\t%d\n", i+1, arrayPrime[i-1]);
61 }
62
63 printf("El primo #%d es:\t%d\n", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]);
64
65 return 0;
66 }