Chapter - 4: The Loop Control Structure

Write a program to add the first seven terms of the following series using a for loop: 1/1! + 2/2! + 3/3! ...


E
Sections
3
Exercises

A

B

C

D

E

1

2

3

4

5

6

7

8

10

11

12

13

14

15

16

9

#include<stdio.h>
#include<conio.h>
int main()
{
	int j;
	float i,fact, sum=0, ser;
	for(i=1;i<=7;i++)
	{
		fact=i;//factorial of the series
		for(j=1;j<i;j++)
			fact=fact*j;
			
		ser=i/fact;//terms of the series
		sum=sum+ser;//sum of the terms of the series
	}
	printf("%f is the sum of the series.", sum);
	getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo