Q::15 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
int f (int n)
{
if (n==0) then
return n;
else
return n + f(n-2);
}
(A)2550 (B)2556
(C)5220 (D)5520
Answer: (A)
Explanation:
f(100)-->(100 + f(98)-->(98 + f(96)-->96 + f(94)........... 2 + f(0) <-- 0
So, it will be an A.P.
2 + 4 +6 +8 + ... + 98 + 100 = n(n+1) {Sum of even numbers upto 'n'}
=50 * 51 = 2550.
Hence, Option A is correct.
UGC-NET Computer Science july 2016 solved paper,UGC-NET Computer Science july 2016 paper 2,cbse-net july 2016 solved paper
ugc net computer science question papers,ugc net computer science december 2014 question papers,
ugc net computer science june 2014 question papers,
ugc net computer science december 2014 question papers,
ugc net computer science june 2013 question papers,
ugc net computer science december 2013 question papers,
ugc net computer science june 2012 question papers,
ugc net computer science december 2012 question papers,
ugc net computer science june 2011 question papers,
ugc net computer science december 2011 question papers,
ugc net computer science june 2010 question papers,
ugc net computer science december 2010 question papers,
ugc net computer science june 2009 question papers,
ugc net computer science december 2009 question papers,
ugc net computer science june 2008 question papers,
ugc net computer science june 2014 question papers,
ugc net computer science december 2014 question papers,
ugc net computer science june 2013 question papers,
ugc net computer science december 2013 question papers,
ugc net computer science june 2012 question papers,
ugc net computer science december 2012 question papers,
ugc net computer science june 2011 question papers,
ugc net computer science december 2011 question papers,
ugc net computer science june 2010 question papers,
ugc net computer science december 2010 question papers,
ugc net computer science june 2009 question papers,
ugc net computer science december 2009 question papers,
ugc net computer science june 2008 question papers,