Question

Write a program to add first seven terms of the following series using a for loop:

sum of series

Source Code

#include <stdio.h>

int main()
{
  int fact = 1, i;
  float sum = 0;

  for (i = 1; i <= 7; i++)
  {
    fact = fact * i;
    sum = sum + 1.0 / fact;
  }

  printf("The sum of series : %f", sum);

  return 0;
}

Output

The sum of series : 1.718254