4 votes 4 votes Algorithms programming recursion made-easy-test-series + – sumit chakraborty asked Jan 28, 2018 • edited Mar 4, 2019 by ajaysoni1924 sumit chakraborty 675 views answer comment Share Follow See all 6 Comments See all 6 6 Comments reply Inspiron commented Jan 28, 2018 i edited by Inspiron Jan 28, 2018 reply Follow Share $13$ and calling from main would also be counted.AFAIK #include<stdio.h> #include<stdlib.h> int f(int x); int main(void){ int value = f(7); printf("%d",value); return 0; } int f(int x){ static int num=1; if(x<=1){ return ; } f(x-2); ++num; f(x-3); ++num; return num; } Excuse me for indentation.! 2 votes 2 votes Tesla! commented Jan 28, 2018 reply Follow Share There is mistake in your code If(x<=1){++x: return;} Because there is no point of any code after return 17 should be answer 0 votes 0 votes Inspiron commented Jan 28, 2018 reply Follow Share @ Tesla! Thanks for correcting ! didn`t get your 17 logic could you please explain? 0 votes 0 votes Tesla! commented Jan 28, 2018 reply Follow Share Correction actually If(x<=1){++x: return;} is not required because this statement is not calling rec() function so whats point of counting and also answer will be 13 0 votes 0 votes sumit chakraborty commented Jan 28, 2018 reply Follow Share Given answer is 13. 0 votes 0 votes sumit chakraborty commented Jan 28, 2018 reply Follow Share Also if you follow this : http://gateoverflow.in/8498/gate2015-3_39, you will get 13. 1 votes 1 votes Please log in or register to add a comment.
0 votes 0 votes rec(7) -> rec(5), rec(4) rec(5)-> rec(3), rec(2) rec(3)-> rec(1), rec(0) rec(2)-> rec(0), rec(-1) rec(4)->rec(2), rec(1) rec(2)->rec(0), rec(-1) This will be flow top down left to right flow Tesla! answered Jan 28, 2018 Tesla! comment Share Follow See all 0 reply Please log in or register to add a comment.