Algorithms | Recursion | Question 9

filter_none

edit
close

play_arrow

link
brightness_4
code

#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;
}

chevron_right


(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




My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.