diff options
author | braxtonhall | 2022-10-23 23:42:08 +0000 |
---|---|---|
committer | braxtonhall | 2022-10-23 23:42:08 +0000 |
commit | 2927387ace15b664d80e2335084e50d478581733 (patch) | |
tree | 77e9c8475ba7c22d4b0e7ca7332abfbba199fe89 /entries/margoseltzer | |
parent | 8c3619fcb5e01b14eeab69bfa8c88cd75ed16ac9 (diff) |
Add Margo's fibs
Diffstat (limited to 'entries/margoseltzer')
-rw-r--r-- | entries/margoseltzer/efficiency.c | 23 |
1 files changed, 23 insertions, 0 deletions
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 |