19. Program to calculate and display sum of the following series using for loop: 1! + 2! + 3! + 4! + 5!

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 19:

Write a program to calculate and display sum of the following series using for loop:
1! + 2! + 3! + 4! + 5!

Solution:

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

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

Previous Post:
18. Program to calculate and display sum of the following series using for loop: x + x^2 + x^3 + ... x^n

Comments