25. Program to add the first seven terms of the following series usign for loop: 1/1! + 2/2! + 3/3!

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 25:

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

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    float f, c, sum=0, n;
    for(n=1;n<=7;n++)
    {
        f=1;
        for(c=1;c<=n;c++)
        {
            f=f*c;
        }
        sum=sum+(n/f);  
    }
    cout<<"Sum of the series is:"<<sum;
    getch();  
}

Let me know in the comment section if you have any question.

Previous Post:
24. Program to print the following sequence: 8 12 17 24 28 33 ... 100

Comments