Skip to content

Instantly share code, notes, and snippets.

@lindslev
Created December 24, 2013 03:16
Show Gist options
  • Select an option

  • Save lindslev/8108336 to your computer and use it in GitHub Desktop.

Select an option

Save lindslev/8108336 to your computer and use it in GitHub Desktop.
This is my solution to problem 7 on Project Euler: What is the 10,001st prime number?
#include <stdio.h>
int main() {
int num = 3;
int count = 0;
int final = 0;
int i = 0;
int isPrime = 3;
while(count < 10000) {
for (i=2; i < num; i++){
if(num%i == 0 && i != num) {
isPrime = 0;
break;
} else {
isPrime = 1;
}
}
if (isPrime == 1) {
final = num;
//printf("final: %d \n", final);
count++;
//printf("count: %d \n", count);
}
num++;
}
printf("final %d \n", final);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment