45 lines
905 B
Ada
45 lines
905 B
Ada
|
-- Ada version of a Prime Number Finder
|
||
|
-- Built with gnatmake 3.15p and gcc 3.2.3
|
||
|
-- haplo@mindstab.net
|
||
|
|
||
|
with Ada.Text_IO, Ada.Numerics.Elementary_Functions, Ada.Command_Line;
|
||
|
use Ada.Text_IO, Ada.Numerics.Elementary_Functions, Ada.Command_Line;
|
||
|
|
||
|
procedure primes is
|
||
|
package int_io is new integer_io(integer);
|
||
|
use int_io;
|
||
|
cnt, i, isPrime, test, MAX : integer;
|
||
|
begin
|
||
|
if argument_count >= 1 then
|
||
|
MAX := integer'value( argument(1) );
|
||
|
else
|
||
|
put_line("Useage: primesada [Max Num]");
|
||
|
return;
|
||
|
end if;
|
||
|
|
||
|
if MAX < 1 then
|
||
|
put_line("Max Num invalid");
|
||
|
return;
|
||
|
end if;
|
||
|
|
||
|
cnt := 3;
|
||
|
while cnt <= MAX loop
|
||
|
test := integer(sqrt(float(cnt)));
|
||
|
isPrime := 1;
|
||
|
i := 3;
|
||
|
while i <= test loop
|
||
|
if cnt mod i = 0 then
|
||
|
isPrime := 0;
|
||
|
exit;
|
||
|
end if;
|
||
|
i := i + 2;
|
||
|
end loop;
|
||
|
if isPrime /= 0 then
|
||
|
put(cnt, width=>0);
|
||
|
new_line(1);
|
||
|
end if;
|
||
|
cnt := cnt + 2;
|
||
|
end loop;
|
||
|
|
||
|
end primes;
|