Functions & Parameter Passing

Answer & solution
Official answer: 46
Resolve the function composition from the innermost call outward. Since g(t)=t+10, f(n)=g(2n)=2n+10. Applying g again gives g(f(n))=f(n)+10=2n+20. The two additions of 10 arise from two separate g calls; the outer one does not double its input.
The loop condition is n<3, so it runs for n=1 and n=2 only. At n=1, f(1)=12 and g(f(1))=22, taking sum from 0 to 22. At n=2, f(2)=14 and g(f(2))=24, taking sum to 46. After incrementing n to 3 the condition fails, and no n=3 term is added. The printed value is 46.




























