Date created: Sunday, July 10, 2011 7:14:48 PM. Last modified: Thursday, December 13, 2012 11:41:20 AM
Problem 7
// Project Euler - Problem 7 #include <stdlib.h> #include <stdio.h> int main (int argc, char *argv[]) { int i = 2; int j = 2; int primecount = 0; int primetop = atoi(argv[1]); while (1) { while (j<=i) { if (i % j != 0) { j++; } else if (i % j == 0) { if (j == i) { primecount++; printf("%d is a prime number %d\n", i, primecount); if (primecount==primetop) { exit (EXIT_SUCCESS); } } j = i + 1; } } j=2; i++; } return EXIT_SUCCESS; }