Program to find sum of series 1!+2!+3!...+n!

Problem statement:- Program to find the sum of series 1!+2!+3!...+n!

 Data requirement:-

   Input Data:- n

  Output Data:-Sum

  Additional Data :-i, fact

Program in C
  
Here is the source code of the C Program to find the sum of series 1!+2!+3!...+n!

Code:

#include<stdio.h>
int main()
{
    int n,sum=0,i,fact=1;
    printf("Enter the range of number:");
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
    fact*=i;
     sum+=fact;
    }

    printf("The sum of the series = %d",sum);
}

Input/Output:
Enter the range of number:7
The sum of the series = 5913

Program in C++
  
Here is the source code of the C++ Program to find the sum of series 1!+2!+3!...+n!

Code:

#include<iostream>
using namespace std;
int main()
{
    int n,sum=0,i,fact=1;
    cout<<"Enter the range of number:";
    cin>>n;

    for(i=1;i<=n;i++)
    {
        fact*=i;
       sum+=fact;
    }
    cout<<"The sum of the series = "<<sum;
}


Input/Output:
Enter the range of number:5
The sum of the series = 153

Program in Java
  
Here is the source code of the Java Program to find the sum of series 1!+2!+3!...+n!

Code:

import java.util.Scanner;
public class p17 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
    int n,sum=0,i,fact=1;
    System.out.println("Enter the range of number:");
    n=cs.nextInt();
    for(i=1;i<=n;i++){
    fact*=i;
        sum+=fact;
    }
    System.out.println("The sum of the series = "+sum);
    cs.close();
}

}

Input/Output:
Enter the range of number:
9
The sum of the series = 409113

Program in Python
  
Here is the source code of the Python Program to find the sum of series 1!+2!+3!...+n!

Code:

print("Enter the range of number:")
n=int(input())
sum=0
fact=1
for i in range(1,n+1):
    fact*=i
    sum+=fact

print("The sum of the series = ",sum)

Input/Output:

Post a Comment

0 Comments