// header files that include standard functions
#include <stdio.h>   // for IO
#include <string.h>  // for manipulating strings
#include <math.h>    // alternate math functions

//the main program
int main()
{
//define variables used in the program
long int irep, n, isave[100000], nprime, j, test;

//initialize the first prime number
isave[0] = 2 ; nprime = 1 ;

//define the output file to be outfile.dat
FILE *outfile ; outfile = fopen("outfile.dat","w") ;

//cycle through the prime numbers up to 100000
 for(irep = 3; irep < 100000 ; irep++)
 {
	 
//test is a dummy variable = 0 if prime and 1 if not prime
 test = 0 ;

//check to see if irep is a prime number
   for(j = 0 ; j < nprime ; j++)
   {
//the % operation is equivalent to taking the remainder
   if((irep%isave[j]) == 0) test = 1 ;
   }

// if a prime number store increment nprime, save in isave and print to file & screen
 if(test == 0)
 {
 nprime ++ ;
 isave[nprime-1] = irep ;
 fprintf(outfile,"%i %i\n",irep,nprime) ;
 if((nprime%10) == 0) printf("%i\n",irep) ;
 }
 }
fclose(outfile) ;
}
