UGC-NET | UGC NET CS 2015 Dec – II | Question 11
Consider the following program :
#include <stdio.h> main( ) { int i, inp; float x, term=1, sum=0; scanf(“%d %f ”, & inp, &x); for(i=1; i<=inp; i++) { term = term * x/i; sum = sum + term ; } printf(“Result = %f\n”, sum); }
The program computes the sum of which of the following series?
(A) x + x2/2 + x3/3 + x4/4 +...
(B) x + x2/2! + x3/3! + x4/4! +...
(C) 1 + x2/2 + x3/3 + x4/4 +...
(D) 1 + x2/2! + x3/3! + x4/4! +...
Answer: (B)
Explanation: Fro i=1:
term = term * x / i = 1 * x / 1 = x.
sum = sum + term = x.
For i = 2:
term = x * x / 2 = x2 / 2.
sum = x + x2 / 2.
For i = 3:
term = x2 / 2 * x / 3 = x3 / 3! .
sum = x + x2 / 2 + x3 / 3!.
and so on...
So, option (B) is correct.
Quiz of this Question