% prime_number_theorem.m
%
%  Compare prime_number_theorem prediction for number of primes
%  bewteen 1 and N to reality.
%
n = input ( 'Enter N: ' );

m = 0;

for i = 2 : n

  itsaprime = true;

  for j = 2 : i - 1 
    if ( mod ( i, j ) == 0 )
      itsaprime = false;
      break
    end
  end

  if ( itsaprime )
    m = m + 1;
  end

end

fprintf ( 'Number of primes between 1 and %d:\n', n );
fprintf ( '  By counting: %d\n', m );
fprintf ( '  Prime number theorem estimate = %f\n', n / log ( n ) );
