5 votes 5 votes The number of times the "return" statement gets executed when the following function is called with an argument $5$ is ______ unsigned int fib(unsigned int n) { if(n == 0) return 0; if(n == 1) return 1; return fib(n-1) + fib(n-2); } Programming in C go2025-programming-1 numerical-answers recursion + – gatecse asked Jul 26, 2020 • edited Jul 26, 2020 by Lakshman Bhaiya gatecse 393 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 7 votes 7 votes Total number of times return statement get executed $=15.$ Lakshman Bhaiya answered Jul 26, 2020 • selected Jul 24, 2021 by Arjun Lakshman Bhaiya comment Share Follow See all 2 Comments See all 2 2 Comments reply nocturnal123 commented Oct 10, 2021 reply Follow Share Used the same approach in solving this question, just wondering is there any formula based(quicker) approach? 0 votes 0 votes Daal_bhaat_enjoyer commented Jan 18 reply Follow Share . 0 votes 0 votes Please log in or register to add a comment.
9 votes 9 votes Number of times return statement getting executed is same as the number of calls to fib. fib(5) = fib(4) + fib(3) + 1 fib(4) = fib(3) + fib(2) + 1 fib(3) = fib(2) + fib(1) + 1 fib(2) = fib(1) + fib(0) + 1 fib(1) = 1 fib(0) = 1 Now, going up we get, fib(2) = 3 fib(3) = 5 fib(4) = 9 fib(5) = 15 gatecse answered Jul 26, 2020 • edited Aug 5, 2020 by Shaik Masthan gatecse comment Share Follow See all 0 reply Please log in or register to add a comment.