Blame view

07 - Primeros 10001 primos/p07.cpp 1007 Bytes
5ec02016e   Francisco Javier Coutiño   p07: Resuelto, bu...
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
65
66
67
68
  /*
  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 };
  
  	bool flgEnd = false;
  
  	do
  	{
  
  		flgEnd = false;
  		numerador = 1;
  		ptrPrime = arrayPrime;
  
  		do
  		{
  
  			while(*ptrPrime != 0)
  			{
  				numerador = *ptrPrime;
  				if (denominador % *ptrPrime++ == 0)
  				{
  					flgEnd = true;
  					break;
  				}
  
  			}
  
  			if( denominador % numerador == 0 && denominador == numerador)
  			{
  				*ptrPrime = denominador;
  				flgEnd = true;
  			}
  
  			numerador++;
  		}while(!flgEnd);
  		denominador++;
  
  	} while (arrayPrime[SIZE_ARRAY] == 0);
  
  	for (int i = 0; i < SIZE_ARRAY; ++i)
  	{
  		printf("%d\t-\t%d
  ", i+1, arrayPrime[i-1]);
  	}
  
  	printf("El primo #%d es:\t%d
  ", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]);
  
  	return 0;
  }