recategorized by
809 views
1 votes
1 votes
#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);
5
return 0;
}

 

(a) 1 4 10    (b) 3 4 5                              
2 4 8            1 4 10
1 8 6             2 4 8
3 4 5             1 8 6
1 5 9             1 5 9
2 5 7             2 5 7
1 7 7              1 7 7

 

(c) 1 4 10     (d) 3 4 5
2 4 8            1 5 9
1 8 6            2 5 7
3 4 5            1 7 7

 

 

 

 

 

please need solution with explaination
recategorized by

2 Answers

1 votes
1 votes

becoz it is a non tail recursion(after the function call there is something to do),so used recursion tree

Related questions

1 votes
1 votes
2 answers
1
Pranav Madhani asked May 26, 2017
1,904 views
int f(int n) { static int i = 1; if (n ≥ 5) return n; n = n + i; i++; return f(n); }The value returned by f(1) is:(a) 5 (b) 6(c) 7 (d) 8 need solution with explaination...
0 votes
0 votes
2 answers
3
Rustam Ali asked Sep 3, 2018
890 views
Find time complexity of below Program?A(n){if(n<=1) return;elsereturn $A(\sqrt{n})$ ;}