diff options
Diffstat (limited to 'src/examples/sieve.ft')
-rw-r--r-- | src/examples/sieve.ft | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/examples/sieve.ft b/src/examples/sieve.ft new file mode 100644 index 0000000..e771009 --- /dev/null +++ b/src/examples/sieve.ft @@ -0,0 +1,48 @@ +!Program to calculate all primes below a certain value +program sieveOfEratosthenes + + !define variables + int::n + n=10000 + int dimension(10000)::checks + int::i + int::j + + !initialise array + do i=2,n + checks(i)=1 + end do + i=2 + + !search for primes + do while(i<root(n)) + if checks(i)==1 then + j=i**2 + do while(j<n) + checks(j)=0 + j=j+i + end do + end if + i=i+1 + end do + + !output primes found + print*,"Primes below ",n + do i=2,n + if checks(i)==1 then + print*,i + end if + end do +end program sieveOfEratosthenes + + +!Function to find the square root of a value +function real root(int value) + real::result + result=1 + int::count + do count=0,10 + result =(result+value/result)/2 + end do + return result +end
\ No newline at end of file |