Question 4Asked in UGC NET Computer Science, December 2015 (Paper II & III, Selected Questions)

Consider the following program : main ( )

Consider the following program : #include < stdio.h> main ( ) { int i, inp; float x, term = 1, sum = 0 scanff ("% f", & inp, &x); for(i = 1, < = inp; i ++) { term = term * x/t; sum = sum + term; } printf("Result = %f\n", sum); } The program computes the sum of which of the following series?
  1. Ax + x²/2 + x³/3 + x⁴/4 +….
  2. Bx + x²/2! + x³/3! + x⁴/4! +….
  3. C1 + x²/2 + x³/3 + x⁴/4 +….
  4. D1 + x²/2! + x³/3! + x⁴/4! +….
Show answerHide answer

Correct answer: (B) x + x²/2! + x³/3! + x⁴/4! +….

Explanation

Initially term = 1, sum = 0. Iteration 1 (i = 1): term = 1 * x/1 = x; sum = x Iteration 2 (i = 2): term = x * x/2 = x²/2; sum = x + x²/2 Iteration 3 (i = 3): term = (x²/2) * x/3 = x³/6; sum = x + x²/2 + x³/6 Iteration 4 (i = 4): term = (x³/6) * x/4 = x⁴/24; sum = x + x²/2 + x³/6 + x⁴/24 This is x/1! + x²/2! + x³/3! + x⁴/4! + ....

From UGC NET Computer Science PYQ, December 2015 (Paper II & III, Selected Questions)

This is question 4 of UGC NET Computer Science PYQ, December 2015 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.