You could store fibs[n-1] + fibs[n-2] in fibb[n] before returning. int fib(int n) { if ( n <= 1 ) { fibb[1]=n; return n; } if(fibb[n] != 0) { return fibb[n]; } fibb[n] = fibs[n-1] + fibs[n-2]; return fibb[n];
//return fibs(n-1)+fibs(n-2); } Thanks 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/-/ev___7tyzPgJ. 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.