From 5eca78af0ff07060b7c740a5be7ce94d7206bf02 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 23 Apr 2022 09:54:47 +0100 Subject: this is also valid C++ code (besides of Raku) --- fibonacci.pl.raku.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 fibonacci.pl.raku.c (limited to 'fibonacci.pl.raku.c') diff --git a/fibonacci.pl.raku.c b/fibonacci.pl.raku.c new file mode 100644 index 0000000..ef1af2b --- /dev/null +++ b/fibonacci.pl.raku.c @@ -0,0 +1,41 @@ +#include + +#define $arg function_argument +#define my int +#define sub int +#define BEGIN int main(void) + +my $arg; + +sub hello() { + printf("Hello, welcome to the Fibonacci Numbers!\n"); + printf("This program is all, valid C and C++ and Perl and Raku code!\n"); + printf("It calculates all fibonacci numbers from 0 to 9!\n\n"); + return 0; +} + +sub fibonacci() { + my $n = $arg; + + if ($n < 2) { + return $n; + } + + $arg = $n - 1; + my $fib1 = fibonacci(); + $arg = $n - 2; + my $fib2 = fibonacci(); + + return $fib1 + $fib2; +} + +BEGIN { + hello(); + my $i = 0; + + while ($i <= 10) { + $arg = $i; + printf("fib(%d) = %d\n", $i, fibonacci()); + $i++; + } +} -- cgit v1.2.3