Thursday, 26 October 2017

Net 32

CBSE NET July 2016 PAPER II

Q. What is the value returned by the function f given below when n=100 ?
int f (int n)
{
if (n==0) then return n;
else
return n + f(n-2);
}

(A) 2550
(B) 2556
(C) 5220
(D) 5520

Ans :- (A)

Explanation:-
It's a recursive function. Its gives output like this, 100+98+96+94+...0. This series of sum shows there is a constant difference of 2. AP gives quick result.
AP = n(nf + nl)/2.

Here n is number of element,nf  is first element of series,nl  is last element of series. So , sum = 50(0+100)/2 = 2550.

Related topics

Professor Jayesh video tutorial

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.