Showing posts with label recursion. Show all posts
Showing posts with label recursion. Show all posts

Sunday, January 10, 2010

With what do you replace the ???? to make the function shown below return the correct answer?

long factorial (long x)
{
????
return x * factorial(x - 1);
}

a) if (x == 0) return 0;
b) return 1;
c) if (x >= 2) return 2;
d) if (x == 0) return 1;
e) if (x <= 1) return 1;

Thursday, April 9, 2009

What is output of following recusive main function call ?

main()
{
static int s=5;
s--;
printf("%d",s);
(s>3)?main():0;
}

Output: 43

Saturday, November 29, 2008

Predict the output of following programme

void myFunc (int x)
{
if (x > 0)
myFunc(--x);
printf("%d, ", x);
}
int main()
{
myFunc(5);
return 0;
}

Choice a: 1, 2, 3, 4, 5, 5,
Choice b: 4, 3, 2, 1, 0, 0,
Choice c: 5, 4, 3, 2, 1, 0,
Choice d: 0, 0, 1, 2, 3, 4,
Choice e: 0, 1, 2, 3, 4, 5,