# Program to find the sum of series 1+X+X^2/2!+X^3/3!...+X^N/N!

Problem statement:- Program to find the sum of series 1+X+X^2/2!+X^3/3!...+X^N/N!

Data requirement:-

Input Data:- n, x

Output Data:-Sum

Program in C

Here is the source code of the C Program to find the sum of series 1+X+X^2/2!+X^3/3!... +X^N/N!

Code:

#include<stdio.h>
#include<math.h>
int main()
{
int n,i=1,x,j,fact;
double sum=1.1;
printf("Enter the range of number:");
scanf("%d",&n);
printf("Enter the value of x:");
scanf("%d",&x);
while(i<=n)
{
fact=1;
for(j=1;j<=i;j++){
fact*=j;
sum+=pow(x,i)/fact;
}
i++;
}
printf("The sum of the series = %0.2lf",sum);
}

Input/Output:
Enter the range of number:5
Enter the value of x:3
The sum of the series = 618.13

Program in C++

Here is the source code of the C++ Program to find the sum of series 1+X+X^2/2!+X^3/3!... +X^N/N!.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i=1,x,j,fact;
double sum=1.0;
cout<<"Enter the range of number:";
cin>>n;
cout<<"Enter the value of x:";
cin>>x;
while(i<=n)
{
fact=1;
for(j=1;j<=i;j++){
fact*=j;
sum+=pow(x,i)/fact;
}
i++;
}
cout<<"The sum of the series = "<<sum;
}

Input/Output:
Enter the range of number:3
Enter the value of x:4
The sum of the series = 135.667

Program in Java

Here is the source code of the Java Program to find the sum of series 1+X+X^2/2!+X^3/3!... +X^N/N!.

Code:

import java.util.Scanner;
public class p12 {

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

Input/Output:
Enter the range of number:
7
Enter the value of x:
2
The sum of the series = 434.4920634920635

Program in Python

Here is the source code of the Python Program to find the sum of series 1+X+X^2/2!+ X^3/3!...+X^N/N!.

Code:

print("Enter the range of number:")
n=int(input())
print("Enter the value of x:")
x=int(input())
sum=1.0
i=1
while(i<=n):
fact=1
for j in range(1,i+1):
fact*=j
sum+=pow(x,i)/fact
i+=1
print("The sum of the series = ",sum)

Input/Output:
Enter the range of number:
7
Enter the value of x:
2
The sum of the series =  434.4920634920635

## C/C++/Java/Python Practice Question

1. 1. 