summaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorAidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com>2021-12-09 02:30:57 +0000
committerAidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com>2021-12-09 02:30:57 +0000
commit13c44054b21d26782e98a52e9a114250ab8307ff (patch)
tree8426476b4daeee01b85cc3f414d04335dbf0a87d /src/examples
parent560a48eebf4f74ae1a21d5cfbb3b55477d7c1356 (diff)
downloadesotericFORTRAN-13c44054b21d26782e98a52e9a114250ab8307ff.tar.gz
esotericFORTRAN-13c44054b21d26782e98a52e9a114250ab8307ff.zip
Added example program of each main feature
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/array.ft13
-rw-r--r--src/examples/conditional.ft11
-rw-r--r--src/examples/doStatement.ft6
-rw-r--r--src/examples/doWhileStatement.ft8
-rw-r--r--src/examples/expression.ft5
-rw-r--r--src/examples/function.ft (renamed from src/examples/example.ft)2
-rw-r--r--src/examples/iteration.ft8
-rw-r--r--src/examples/selection.ft6
-rw-r--r--src/examples/sieve.ft48
-rw-r--r--src/examples/string.ft5
-rw-r--r--src/examples/subroutine.ft9
11 files changed, 106 insertions, 15 deletions
diff --git a/src/examples/array.ft b/src/examples/array.ft
new file mode 100644
index 0000000..6f62940
--- /dev/null
+++ b/src/examples/array.ft
@@ -0,0 +1,13 @@
+program array
+int dimension(10)::a
+int::i
+
+do i=0,9
+a(i)=i*2
+end do
+
+do i=0,9
+print*,a(i)
+end do
+
+end program array \ No newline at end of file
diff --git a/src/examples/conditional.ft b/src/examples/conditional.ft
new file mode 100644
index 0000000..6d3f79d
--- /dev/null
+++ b/src/examples/conditional.ft
@@ -0,0 +1,11 @@
+program conditional
+int::a
+int::b
+a=5
+b=7
+if a>=b then
+print*,a," is greater than or equal to ",b
+else
+print*,a," is less than ",b
+end if
+end program conditional \ No newline at end of file
diff --git a/src/examples/doStatement.ft b/src/examples/doStatement.ft
new file mode 100644
index 0000000..ddee000
--- /dev/null
+++ b/src/examples/doStatement.ft
@@ -0,0 +1,6 @@
+program doStatement
+int::i
+do i=0,10
+print*,i
+end do
+end program doStatement \ No newline at end of file
diff --git a/src/examples/doWhileStatement.ft b/src/examples/doWhileStatement.ft
new file mode 100644
index 0000000..a8aa096
--- /dev/null
+++ b/src/examples/doWhileStatement.ft
@@ -0,0 +1,8 @@
+program doWhileStatement
+int::i
+i=0
+do while(i<=10)
+print*,i
+i=i+1
+end do
+end program doWhileStatement \ No newline at end of file
diff --git a/src/examples/expression.ft b/src/examples/expression.ft
new file mode 100644
index 0000000..c3420fe
--- /dev/null
+++ b/src/examples/expression.ft
@@ -0,0 +1,5 @@
+program expression
+int::a
+a=(5+4)*(10/2)+5**2
+print*,a
+end program expression \ No newline at end of file
diff --git a/src/examples/example.ft b/src/examples/function.ft
index 571cace..2c6ed7d 100644
--- a/src/examples/example.ft
+++ b/src/examples/function.ft
@@ -2,7 +2,7 @@ program example
real::a
real::root
a=30
-root=sqrt(25+5)
+root=sqrt(a)
print*,"The square root of ",a," is ",root
end program example
diff --git a/src/examples/iteration.ft b/src/examples/iteration.ft
deleted file mode 100644
index 22a2bfb..0000000
--- a/src/examples/iteration.ft
+++ /dev/null
@@ -1,8 +0,0 @@
-int dimension(5)::test
-int::i
-do i=0,4
-test(i)=i
-end do
-do i=0,4
-print*,test(i)
-end do \ No newline at end of file
diff --git a/src/examples/selection.ft b/src/examples/selection.ft
deleted file mode 100644
index 21100b2..0000000
--- a/src/examples/selection.ft
+++ /dev/null
@@ -1,6 +0,0 @@
-character (len=10)::hello
-hello="hello"
-if 4==5 then
-hello="goodbye "
-endif
-print *,hello,6," world" endprint \ No newline at end of file
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
diff --git a/src/examples/string.ft b/src/examples/string.ft
new file mode 100644
index 0000000..dc7ed08
--- /dev/null
+++ b/src/examples/string.ft
@@ -0,0 +1,5 @@
+program string
+character(len=15)::a
+a="Hello World!"
+print*,a
+end program string \ No newline at end of file
diff --git a/src/examples/subroutine.ft b/src/examples/subroutine.ft
new file mode 100644
index 0000000..58171b8
--- /dev/null
+++ b/src/examples/subroutine.ft
@@ -0,0 +1,9 @@
+program subroutineExample
+calc(3,4,5)
+end program subroutineExample
+
+subroutine calc(int a,int b,int c)
+int::total
+total=a*b*c
+print*,total
+end \ No newline at end of file