primes/primes.f

30 lines
548 B
FortranFixed
Raw Normal View History

2011-03-08 07:01:27 +00:00
c Fortran version of a Prime Number Finder
c haplo@mindstab.net
program primes
implicit none
real test, i;
integer isPrime, amax, cnt;
character *32 buff;
if (iargc() >= 1) then
call getarg(1, buff);
read(buff, *) amax;
else
print*, "Useage: primesf [Max Num]";
return
endif
do cnt = 3, amax, + 2
test = sqrt(float(cnt));
isPrime=1;
do test = 3, test, +2
2013-01-31 06:37:55 +00:00
if (mod(cnt, int(test)) == 0) then
2011-03-08 07:01:27 +00:00
isPrime=0;
exit;
endif
enddo
if(isPrime /= 0) print*,cnt
c if(isPrime /= 0) write(*,'(I3.1)'),cnt
enddo
end