Exercise 5-2. Define an array, data, with elements of type double. Write a loop that
Would store the following sequence of values in corresponding elements of the array:
1/(2*3*4) 1/(4*5*6) 1/(6*7*8) ... up to 1/(200*201*202)
Write another loop that would calculate the following:
DATA[0]-data[1] + data[2]-data[3] + ...-data[99]
Multiply The result of this by 4.0, add 3.0, and output the final result. Do you recognize the
Value you get?
1 //Exercise 5.2 Summing data values2#include <stdio.h>3 4 intMainvoid)5 {6 Doubledata[ -];//Stores Data Values7 Doublesum =0.0;//Stores sum of terms8 DoubleSign =1.0;//sign-flips between +1.0 and-1.09size_t i =0;Ten One intj =0; A for(i =0; I <sizeof(data)/sizeof(Double) ; ++i)//God horse means? - { -j =2* (i +1); theData[i] =1.0/(J * (J +1) * (j +2)); -Sum + = sign*Data[i]; -Sign =-Sign ; - } + - //Output The result +printf"The result is%.4lf\n",4.0*sum +3.0); Aprintf"The result is a approximation of pi, isn ' t that interesting?\n"); at return 0; -}
Exercise 5.2 Summing data values