GATE CS 2026 Set 2 | Question 61
Programming & Data Structures › Functions · NAT · 2 marks · Answer: 1
- Question 61Programming & Data Structuresnat2 marksConsider the following ANSI-C function.
The maximum possible value that can be returned from this function is __________. (answer in integer)cint func(int start, int end){ int length=end+1-start; if((length<1)||(start<0)||(end<0)){ return(0); } if(length%3==0){ return(func(start+1, end)); } else if(length%3==1){ return(1+func(start, end-1)); } else { return(func(start+2, end)); } }Answer: 1
Solution
The return value depends only on . Let be the value: - : . - : . - : . - : . Computing: The value never exceeds .
More GATE PYQ on Functions
All GATE CS Programming & Data Structures PYQ →Attempt GATE CS 2026 Set 2 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →