Find sum of series (1+(1*2)+(1*2*3)+...till N)

Problem statement:- Program to find the sum of series (1+(1*2)+(1*2*3)+...till N).


Sample Input/Output:-


Sample Input First:

7

Sample Output First: 

5913

Sample Input Second: 

8

Sample Output Second: 

46233


 
Data requirement:-

   Input Data:- n

  Output Data:- sum_series

  Additional Data:-i, j, multiply

Program in C
  

Here is the source code of the C Program to find the sum of series (1+(1*2)+(1*2*3)+...till N).


Code:

#include <stdio.h>
int main()
{
  int ni = 1,sum_series0;
  /* Get the N Value */
  printf("Enter the range of number:");
  scanf("%d", &n);
  while (i <= n)
  {
    int multiply1,j;
    for (j = 1j <= ij++)
    {
      multiply*= j;
    }
    sum_series += multiply;
    i++;
  }
  printf("The sum of the series = %d"sum_series);
}


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+(1*2)+(1*2*3)+...till N).


Code:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int ni = 1sum_series = 0;
    /* Get the N Value */
    cout << "Enter the range of number:";
    cin >> n;
    while (i <= n)
    {
        int multiply = 1j;
        for (j = 1j <= ij++)
        {
            multiply *= j;
        }
        sum_series += multiply;
        i++;
    }
    cout << "The sum of the series = " << sum_series;
}


Input/Output:
Enter the range of number:8
The sum of the series = 46233

Program in Java
  

Here is the source code of the Java Program to find the sum of series (1+(1*2)+(1*2*3)+...till N).


Code:

import java.util.Scanner;

public class SumOfSeries {

    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);
        int ni = 1sum_series = 0;
        /* Get the N Value */
        System.out.println("Enter the range of number:");
        n = cs.nextInt();
        while (i <= n) {
            int multiply = 1j;
            for (j = 1j <= ij++) {
                multiply *= j;
            }
            sum_series += multiply;
            i++;
        }
        System.out.println("The sum of the series = " + sum_series);
        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+(1*2)+(1*2*3)+...till N).

Code:

# Get the N Value 
n=int(input("Enter the range of number:"))
sum_series=0
i=1
while(i<=n):
    multiply=1
    for j in range(1,i+1):
        multiply*=j
    sum_series+=multiply
    i+=1
print("The sum of the series = ",sum_series)


Input/Output:
Enter the range of number:
11
The sum of the series =  43954713


Post a Comment

0 Comments