#!/usr/local/bin/gentee -r

func main<main>
{
   str   input
   uint  high i j
   
   print("This program uses \"The Sieve of Eratosthenes\" for finding prime numbers.\n\n")
   high = uint( congetstr("Enter the high limit number ( < 100000 ): ", input ))
   if high > 100000 : high = 100000
	
   arr  sieve[ high + 1 ] of byte
   
   fornum i = 2, high/2 + 1
   {
      if !sieve[ i ]
      {
         j = i + i
         while j <= high
         {
            sieve[ j ] = 1
            j += i
         }
      }
   }
   j = 0
   input.setlen( 0 )

   fornum i = 2, high + 1
   {
      if !sieve[ i ]
      {
         int2str( input, "%8u", i )
         if ++j == 10 
         {
            j = 0
            input += "\l"
         }
      }
   }

   input.write( "prime.txt" )
   shell( "/bin/cat prime.txt" )
}
