You could update fibb[n] before returning fib(n-1) + fib(n-2) int fib(int n) { if ( n <= 1 ) { fibb[1]=n; return n; } if (fibb[n] ! = 0 ) {
//return fibs(n-1)+fibs(n-2); } On Sunday, October 21, 2012 7:46:43 AM UTC-4, rahul sharma wrote: > > #include<stdio.h> > int fib(int n) > { > if ( n <= 1 ) > return n; > return fib(n-1) + fib(n-2); > } > > How can we reduce no of computations with the above code....(iterative > solution not allowed). > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/AgmaPZ-P3DIJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.