retagged by
1,894 views

2 Answers

Best answer
0 votes
0 votes

Static storage class allows to initialize a variable for one time and re-initialization can't be done till end of program 

execution of f(1)

i=1

n=2

i=2

call f(2)

i=2

n=4

i=3

call f(3)

i=3

n=7

i=4

call f(7)

since n >= 5 so return n(7)

selected by
0 votes
0 votes
yeah the question is correct. Here the static initialization is executed only once through out the execution of program.so i is intialized to 1 only once and then it keeps on increasing its value.in

1 step- f(1) since n =1,it gets incremented by i.i.e n=2.then i++ makes i=2.

2 step-f(2)since n=2,it gets incremented by i(.i.e n=2+2.)then i++ makes i=3.

3 step-f(4)since n=4,it gets incremented by i(.i.e n=4+3.)then i++ makes i=4.

4 step-f(7)since n>=5 is satisfied returns n value. i.e->n=7

so answer is 7

Related questions

0 votes
0 votes
2 answers
3
Rustam Ali asked Sep 3, 2018
884 views
Find time complexity of below Program?A(n){if(n<=1) return;elsereturn $A(\sqrt{n})$ ;}