primes/primes.fe

37 lines
631 B
Plaintext
Executable File

#!/usr/bin/env ferite
/* Ferite version of a Prime Number Finder
* haplo@mindstab.net */
uses "array", "console", "math";
array fncArgs;
number MAX, cnt, test, i, remainder;
string foo;
MAX = 10;
foo = Console.readln();
foo = String.trim(foo, "\n");
if(String.isNumber(foo))
{
MAX = String.toNumber(foo);
} else {
Console.println("Useage: primes.fe [Max Num]\n");
}
if(MAX < 1) { Console.println("Invalid Max Num\n"); }
i = 0;
for(cnt = 3; cnt <= MAX; cnt +=2)
{
test = Math.sqrt(cnt);
remainder=1;
for(i=3; i<= test; i+=2)
{
remainder = cnt%i;
if(! remainder) break;
}
if(remainder)
Console.println(cnt);
}