Problem statement:- Program to find the sum of series (1+(1*2)+(1*2*3)+...till N).
Sample Input/Output:-
Data requirement:-
Input Data:- n
Output Data:- sum_series
Additional Data:-i, j, multiply
Program in C
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 n, i = 1,sum_series= 0; /* Get the N Value */ printf("Enter the range of number:"); scanf("%d", &n); while (i <= n) { int multiply= 1,j; for (j = 1; j <= i; j++) { multiply*= j; } sum_series += multiply; i++; } printf("The sum of the series = %d", sum_series);}
#include <stdio.h>int main(){ int n, i = 1,sum_series= 0; /* Get the N Value */ printf("Enter the range of number:"); scanf("%d", &n); while (i <= n) { int multiply= 1,j; for (j = 1; j <= i; j++) { 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
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 n, i = 1, sum_series = 0; /* Get the N Value */ cout << "Enter the range of number:"; cin >> n; while (i <= n) { int multiply = 1, j; for (j = 1; j <= i; j++) { multiply *= j; } sum_series += multiply; i++; } cout << "The sum of the series = " << sum_series;}
#include <iostream>#include <cmath>using namespace std;int main(){ int n, i = 1, sum_series = 0; /* Get the N Value */ cout << "Enter the range of number:"; cin >> n; while (i <= n) { int multiply = 1, j; for (j = 1; j <= i; j++) { 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
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 n, i = 1, sum_series = 0; /* Get the N Value */ System.out.println("Enter the range of number:"); n = cs.nextInt(); while (i <= n) { int multiply = 1, j; for (j = 1; j <= i; j++) { multiply *= j; } sum_series += multiply; i++; } System.out.println("The sum of the series = " + sum_series); cs.close(); }}
import java.util.Scanner;
public class SumOfSeries {
public static void main(String[] args) { Scanner cs = new Scanner(System.in); int n, i = 1, sum_series = 0; /* Get the N Value */ System.out.println("Enter the range of number:"); n = cs.nextInt(); while (i <= n) { int multiply = 1, j; for (j = 1; j <= i; j++) { 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
9
The sum of the series = 409113
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=0i=1while(i<=n): multiply=1 for j in range(1,i+1): multiply*=j sum_series+=multiply i+=1print("The sum of the series = ",sum_series)
# Get the N Value n=int(input("Enter the range of number:"))sum_series=0i=1while(i<=n): multiply=1 for j in range(1,i+1): multiply*=j sum_series+=multiply i+=1print("The sum of the series = ",sum_series)
Input/Output:
Enter the range of number:
11
The sum of the series = 43954713
11
The sum of the series = 43954713
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box