// Program to compute prime numbers
// KJC (prime.c - 09/07/04)
#include <stdio.h>
#include <math.h>

#define MAX  2000000

void main()
{
  int test_val;
  int prime_flag;
  int prime_count;
  int i, j;

  prime_count = 1;  // init to 1 because 2 is prime
  for (i=3; i<MAX; i=i+2)
  {
    test_val = (int) sqrt((double) i);
    prime_flag = 1;
    for (j=3; j<=test_val; j=j+2)
      if ((i % j) == 0) prime_flag = 0;
    if (prime_flag == 1) prime_count++;
  }

  printf("prime_count = %d \n", prime_count);
}

