lucproblem009.c (427B)
1 /* Write a program to add first seven terms of the following series using a 2 for loop. 3 1 / 1! + 2 / 2! + 3 / 3! + ... 4 */ 5 /* Let Us C, Chap - 6, Page - 102, Problem 6.2 */ 6 7 #include <stdio.h> 8 #define N 7 // update N here 9 10 int main() 11 { 12 double sum = 0; int fact = 1; 13 for (int i = 1; i <= N; i++) 14 { 15 fact *= i; 16 sum += (double)i / fact; 17 } 18 printf("Sum of the series : %g", sum); 19 return 0; 20 }