Ad

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! ...


Ad
E
Sections
3
Exercises
#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;
}
Ad

© 2024 Garbage Valuegarbage value logo