aboutsummaryrefslogtreecommitdiff
path: root/entries/ionathanch/fib.f90
diff options
context:
space:
mode:
authorfunemy2022-10-25 07:14:52 +0000
committerfunemy2022-10-25 07:14:52 +0000
commit998ef837b43203319397f191036a97a5adc42220 (patch)
tree920558bd60d282c663fd2da1cd4144cac1849a1d /entries/ionathanch/fib.f90
parentfdac6c60e115297a58f5b81da0c4b7f18ac758f2 (diff)
parentce7544a6db594f7d3dfad0d7dc65d01515e57ad6 (diff)
Merge branch 'main' of github.com:braxtonhall/fib
Diffstat (limited to 'entries/ionathanch/fib.f90')
-rw-r--r--entries/ionathanch/fib.f9021
1 files changed, 21 insertions, 0 deletions
diff --git a/entries/ionathanch/fib.f90 b/entries/ionathanch/fib.f90
new file mode 100644
index 0000000..3cf1850
--- /dev/null
+++ b/entries/ionathanch/fib.f90
@@ -0,0 +1,21 @@
+PROGRAM main
+ ! The 93rd Fibonacci number is the largest that fits in 64 bits anyway
+ CHARACTER(3) :: kth
+ INTEGER :: k
+ CALL get_command_argument(1, kth)
+ READ(kth, *) k
+ WRITE(*, *) fib(k)
+CONTAINS
+
+PURE RECURSIVE INTEGER*8 FUNCTION fib(k) RESULT(n)
+ INTEGER, INTENT (IN) :: k
+ IF (k == 0) THEN
+ n = 0
+ ELSE IF (k == 1) THEN
+ n = 1
+ ELSE
+ n = fib(k - 1) + fib(k - 2)
+ END IF
+END FUNCTION fib
+
+END PROGRAM