From 694ec05bcad01fd27606aace73b49cdade16945e Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 19 Aug 2017 11:05:43 +0200 Subject: Initial --- fibo.lang | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 fibo.lang (limited to 'fibo.lang') 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; +} -- cgit v1.2.3-70-g09d2