diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-08-19 11:05:43 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-08-19 11:05:43 +0200 |
commit | 694ec05bcad01fd27606aace73b49cdade16945e (patch) | |
tree | 5c7a0433232f0860ef18f1634510d4f823ce5bdb /fibo.lang |
Initial
Diffstat (limited to 'fibo.lang')
-rw-r--r-- | fibo.lang | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/fibo.lang b/fibo.lang new file mode 100644 index 0000000..e1a7a4a --- /dev/null +++ b/fibo.lang @@ -0,0 +1,31 @@ +func printnum(int n) { + if (n == 0) {putc('0'); return;} + if (n < 0) {putc('-'); n = -n;} + while (n > 0) { + putc('0' + char(n % 10)); + n = n / 10; + } +} + +func int fibo(int n) { + int a := 0; + int b := 1; + int i := 0; + while (i < n) { + int c := a + b; + a = b; + b = c; + i = i + 1; + } + return b; +} + +func int main() { + int i := 0; + while (i <= 20) { + printnum(fibo(i)); + putc('\n'); + i = i + 1; + } + return 0; +} |