/* 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 #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\n", i+1, arrayPrime[i-1]); } printf("El primo #%d es:\t%d\n", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]); return 0; }