Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

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.

Leave a Comment