summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (mars.fritz.box) <paul@buetow.org>2014-03-24 23:47:33 +0100
committerPaul Buetow (mars.fritz.box) <paul@buetow.org>2014-03-24 23:47:33 +0100
commitdb39d8b3d6a32e6c2320c8d765b4b969ea3399db (patch)
treeab598e01079113fce4a89f5a290314cc9bd3f963
initial import
-rw-r--r--Makefile5
-rw-r--r--fibonacci.pl.c42
-rw-r--r--out.txt32
3 files changed, 79 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4a4eec7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+all:
+ gcc fibonacci.pl.c -o fibonacci
+ ./fibonacci
+ @echo
+ perl fibonacci.pl.c
diff --git a/fibonacci.pl.c b/fibonacci.pl.c
new file mode 100644
index 0000000..9f45b12
--- /dev/null
+++ b/fibonacci.pl.c
@@ -0,0 +1,42 @@
+#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 Perl-C!\n");
+ printf("This program is both, valid C and Perl 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;
+
+ for ($i = 0; $i <= 10; ++$i) {
+ $arg = $i;
+ printf("fib(%d) = %d\n", $i, fibonacci());
+ }
+
+ return 0;
+}
diff --git a/out.txt b/out.txt
new file mode 100644
index 0000000..86a9882
--- /dev/null
+++ b/out.txt
@@ -0,0 +1,32 @@
+gcc fibonacci.pl.c -o fibonacci
+./fibonacci
+Hello, welcome to Perl-C!
+This program is both, valid C and Perl code!
+It calculates all fibonacci numbers from 0 to 9!
+
+fib(0) = 0
+fib(1) = 1
+fib(2) = 1
+fib(3) = 2
+fib(4) = 3
+fib(5) = 5
+fib(6) = 8
+fib(7) = 13
+fib(8) = 21
+fib(9) = 34
+
+perl fibonacci.pl.c
+Hello, welcome to Perl-C!
+This program is both, valid C and Perl code!
+It calculates all fibonacci numbers from 0 to 9!
+
+fib(0) = 0
+fib(1) = 1
+fib(2) = 1
+fib(3) = 2
+fib(4) = 3
+fib(5) = 5
+fib(6) = 8
+fib(7) = 13
+fib(8) = 21
+fib(9) = 34