The Gateway to Computer Science Excellence
+2 votes
294 views
Consider the following function:
void madeeasy (int n)
{
if (n < 0) return;
else
{
printf(n);
madeeasy (- -n);
madeeasy (n - -);
printf(n);
}
}
The sum of all values printed by madeeasy (5)_______

(I am getting -12 but given answer is 52)
in Programming by Active (1.7k points) | 294 views
0
temination condition is on n<0 ;

52 is answer if termination condition is n<=0
0
Yes..even i got -12..there are lot of mistakes in ME mocks
0

@balchandar reddy san

Consider the following code:
int P = 0;
for (i = 1; i < 2n; i++)
{
for (j = 1, j<=n; j++)
{
if(j<i) P=P+1;
}
}
printf(“%d”, P);

What is the output printed by the above code in terms of n?

 

what about this i calculated ans as  (3*$n^{2}$-3*n)/2 but in answer they have given (3*$n^{2}$-n)/2

0

Yes..they have given the solution by assuming:

for (i = 1; i <= 2n; i++)

Even i got the same...

0
hmm.thanks!
0

@newdreamz a1-z0 one question, what do you feel is the answer for this https://gateoverflow.in/301271/me-mock-4,?

0
i was sure only with the first part .second part i did'nt get.
0
Too lengthy to solve!
0
0

But how you get 12 ??? @balchandar reddy san

please tell me the answer..

0

refer here: https://gateoverflow.in/301258/me-mock-4 for the answer given

2 Answers

+3 votes
Best answer

Anwer is -12

by Active (3.3k points)
selected by
+1
0 votes

Case 1 : If termination condition is on n<0 ;

if (n < 0)

then answer will be -12

 

Case 2 : if termination condition is n<=0

if (n <= 0)

then answer will be  52

by (147 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,297 answers
198,262 comments
104,976 users