Algorithms | Recursion | Question 9

1.5
#include<stdio.h>
void crazy(int n,int a,int b)
{
    if (n <= 0)  return;
    crazy(n-1, a, b+n);
    printf("%d %d %d\n",n,a,b);
    crazy(n-1, b, a+n);
}

int main()
{
    crazy(3,4,5);
    return 0;
}

(A)

1 4 10
2 4 8
1 8 6
3 4 5
1 5 9
2 5 7
1 7 7

(B)

3 4 5
1 4 10
2 4 8
1 8 6
1 5 9
2 5 7
1 7 7

(C)

1 4 10
2 4 8
1 8 6
3 4 5

(D)

3 4 5
1 5 9
2 5 7
1 7 7


Answer: (A)

Explanation:

Quiz of this Question

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:



1.5 Average Difficulty : 1.5/5.0
Based on 2 vote(s)










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.