diff options
author | AidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com> | 2021-12-09 02:30:57 +0000 |
---|---|---|
committer | AidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com> | 2021-12-09 02:30:57 +0000 |
commit | 13c44054b21d26782e98a52e9a114250ab8307ff (patch) | |
tree | 8426476b4daeee01b85cc3f414d04335dbf0a87d /src/examples/sieve.ft | |
parent | 560a48eebf4f74ae1a21d5cfbb3b55477d7c1356 (diff) | |
download | esotericFORTRAN-13c44054b21d26782e98a52e9a114250ab8307ff.tar.gz esotericFORTRAN-13c44054b21d26782e98a52e9a114250ab8307ff.zip |
Added example program of each main feature
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 |