Deitel & Deitel, C How to Program 6th Edition, Exercise 5.48 (Research Project: Improving the Recursive Fibonacci Implementation)
/*5.48 (Research Project: Improving the Recursive Fibonacci Implementation) In Section 5.15, the
recursive algorithm we used to calculate Fibonacci numbers was intuitively appealing. However, recall
that the algorithm resulted in the exponential explosion of recursive function calls. Research the
recursive Fibonacci implementation online. Study the various approaches, including the iterative
version in Exercise 5.35 and versions that use only so-called “tail recursion.” Discuss the relative
merits of each.*/
#include <stdio.h>
int main() {
int i, fibo1 = 0, fibo2 = 1, fibo3;
for (i = 1; i < 50; i++) {
fibo3 = fibo1 + fibo2;
i % 2 == 1 ? fibo2 = fibo3 : 0;
i % 2 == 0 ? fibo1 = fibo3 : 0;
printf("%d-)%d\n", i, fibo3);
}
printf("\n");
return 0;
}
recursive algorithm we used to calculate Fibonacci numbers was intuitively appealing. However, recall
that the algorithm resulted in the exponential explosion of recursive function calls. Research the
recursive Fibonacci implementation online. Study the various approaches, including the iterative
version in Exercise 5.35 and versions that use only so-called “tail recursion.” Discuss the relative
merits of each.*/
#include <stdio.h>
int main() {
int i, fibo1 = 0, fibo2 = 1, fibo3;
for (i = 1; i < 50; i++) {
fibo3 = fibo1 + fibo2;
i % 2 == 1 ? fibo2 = fibo3 : 0;
i % 2 == 0 ? fibo1 = fibo3 : 0;
printf("%d-)%d\n", i, fibo3);
}
printf("\n");
return 0;
}
Let me know in the comments if this page helped you somehow.
It is nice to know if my work helped someone, thanks :)
Comments
Post a Comment