summaryrefslogtreecommitdiff
path: root/fibonacci.pl.raku.c
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-04-23 09:54:47 +0100
committerPaul Buetow <paul@buetow.org>2022-04-23 09:54:47 +0100
commit5eca78af0ff07060b7c740a5be7ce94d7206bf02 (patch)
tree9cce4b94ee307f3898718cf0abca3315ea8c2cdb /fibonacci.pl.raku.c
parent932844e590156a2bf9d970151382aae50acc30c4 (diff)
this is also valid C++ code (besides of Raku)
Diffstat (limited to 'fibonacci.pl.raku.c')
-rw-r--r--fibonacci.pl.raku.c41
1 files changed, 41 insertions, 0 deletions
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 <stdio.h>
+
+#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++;
+ }
+}