Define an array, data, with 100 elements of type double. Write a loop that will 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 will 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 that you get?


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>

void main(void)
{
	int i;	// counter
	double data[100]; 
	double sum = 0.0;
	double sign = 1.0;


	for(i = 1 ; i<=100 ; i++)
    		data[i-1] = 1.0/(2*i*(2*i+1)*(2*i+2));

  	for(i = 0 ; i<100 ; i++)
  	{
    		sum += sign*data[i];
    		sign = -sign;
  	}

  	printf("\nThe result is %.4lf\n", 4.0*sum+3);
}


Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Removing negative numbers from a stack