prime number generation, match 10001 prime number
Please help. I've been playing around with this code most of the day, or for a couple days, trying to find a way to insert "10001" after program execution to find the matching answer (this is on project euler) and it's question #7 Problem 7 - Project Euler
Code:
#include <stdio.h>
#include <stdbool.h>
int main ()
{
int p;
int d;
int input;
int ctr = 1;
bool isPrime;
printf("What prime number do you want to find: ");
scanf("%d", &input); // ask for users input of prime number to find
for (p = 2; ; ++p) { // cycle through integers 2 through infinite
isPrime = true;
for(d = 2; d < p; ++d) // divide p by by -1
if(p % d == 0) // factor found (for example, 2)
isPrime = false;
if(isPrime != false) // isPrime is true (for example, no factors)
// var number total count number of isPrime != false variables (incrememnt ctr for each one)
printf("%d\n", p);
}
printf("\n");
return 0;
}
Well, how do I access p from the first loop, is my first question, for the printf statement under the
Code:
if(isPrime != false)
printf("%d\t%d\n", p);
For example, i was thinking of doing something like this, my coding experience is beginner,
Code:
if(isPrime != false)
if(p > 1)
++ctr;
if(ctr == input)
printf("%d\n", p);
or my other option was
Code:
if(isPrime != false && /* insert something else here */)