From 2927387ace15b664d80e2335084e50d478581733 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Sun, 23 Oct 2022 16:42:08 -0700 Subject: Add Margo's fibs --- entries/margoseltzer/efficiency.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 entries/margoseltzer/efficiency.c (limited to 'entries/margoseltzer/efficiency.c') diff --git a/entries/margoseltzer/efficiency.c b/entries/margoseltzer/efficiency.c new file mode 100644 index 0000000..6e017f3 --- /dev/null +++ b/entries/margoseltzer/efficiency.c @@ -0,0 +1,23 @@ +unsigned long foo(unsigned long n) { + if (n < 2) return (n); + return(foo(n - 1) + foo(n - 2)); +} + +// Efficiency of expression + +unsigned long bar(unsigned long n) { + unsigned long i, last; + unsigned long sum, tmp; + + if (n < 2) return (n); + last = 0; + sum = 1; + for (i = 2; i <= n; i++) { + tmp = sum; + sum += last; + last = tmp; + } + return (sum); +} + +// Efficiency in resource utilization -- cgit v1.2.3-70-g09d2