Let

*n*= 3,*then , x*is converted to radian by multiplying it by 3.14159/180 and assigned the value of

*x in*

*t*and

*sum*

. So, after line no 15 and 16,

*t = x*and*sum = x*Now lets take a look at the working of for loop with

*n*= 3:Ex1: t = (t * pow((double) (-1), (double) (2 * i – 1)) * x * x) / (2 * i * (2 * i + 1))

Ex2: sum = sum + t

**Iteration 1: i = 1, t = x, sum = x**

Putting these values in Ex 1 we get,

t = (x * pow((double) (-1), (double) (2 * 1 – 1)) * x * x) / (2 * 1 * (2 * 1 + 1))

t = x*(-1)*x*x/6 = -x

^{3}/3!Putting value of t in Ex 2 we get,

sum = x + (-x

^{3}/3! ) = x – x^{3}/3!**Iteration 2: i = 2, t =**

**-x**

^{3}/3!, sum = x – x^{3}/3!Putting these values in Ex 1 we get,

t = (-x

^{3}/3! * pow((double) (-1), (double) (2 * 2 – 1)) * x * x) / (2 * 2 * (2 * 2 + 1))t = (-x

^{3}/3!)*(-1)*x*x/20 = x^{5}/5!Putting value of t in Ex 2 we get,

sum = x – x

^{3}/3! + x^{5}/5!**Iteration 3: i = 3, t = x**

^{5}/5!, sum = x – x^{3}/3! + x^{5}/5!Putting these values in Ex 1 we get,

t = (x

^{5}/5! * pow((double) (-1), (double) (2 * 3 – 1)) * x * x) / (2 * 3 * (2 * 3 + 1))t = (x

^{5}/5!)*(-1)*x*x/42 = -x^{7}/7!Putting value of t in Ex 2 we get,

sum = x – x

^{3}/3! + x^{5}/5! – x^{7}/7!After iteration 3, i = 4 so the for loop terminates and output is printed.

Leave a comment