Problem Statement:- Program to find the sum of series 1!/1+2!/2+3!/3+4!/4+5!/5 ...+n!/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!/1+2!/2+3!/3...+n!/n
Code:
#include<stdio.h>
int main()
{
int n,i,fact=1;
double sum=0.0;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact*=i;
sum+=fact/i;
}
printf("The sum of the series = %0.2lf",sum);
}
int main()
{
int n,i,fact=1;
double sum=0.0;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact*=i;
sum+=fact/i;
}
printf("The sum of the series = %0.2lf",sum);
}
Input/Output:
Enter the range of number:5
The sum of the series = 34.00
The sum of the series = 34.00
Program in C++
Here is the source code of the C++ Program to find the sum of series 1!/1+2!/2+3!/3...+n!/n
Code:
#include<iostream>
using namespace std;
int main()
{
int n,i,fact=1;
double sum=0.0;
cout<<"Enter the range of number:";
cin>>n;
for(i=1;i<=n;i++)
{
fact*=i;
sum+=fact/i;
}
cout<<"The sum of the series = "<<sum;
}
using namespace std;
int main()
{
int n,i,fact=1;
double sum=0.0;
cout<<"Enter the range of number:";
cin>>n;
for(i=1;i<=n;i++)
{
fact*=i;
sum+=fact/i;
}
cout<<"The sum of the series = "<<sum;
}
Input/Output:
Enter the range of number:7
The sum of the series = 874
Program in Java
The sum of the series = 874
Program in Java
Here is the source code of the Java Program to find the sum of series 1!/1+2!/2+3!/3...+n!/n
Code:
import java.util.Scanner;
public class p18 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,fact=1;
double sum=0.0;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++){
fact*=i;
sum+=fact/i;
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
}
public class p18 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,fact=1;
double sum=0.0;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++){
fact*=i;
sum+=fact/i;
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
}
Input/Output:
Enter the range of number:
11
The sum of the series = 4037914.0
Program in Python
11
The sum of the series = 4037914.0
Program in Python
Here is the source code of the Python Program to find the sum of series 1!/1+2!/2+3!/3...+ n!/n
Code:
print("Enter the range of number:")
n=int(input())
sum=0.0
fact=1
for i in range(1,n+1):
fact*=i
sum+=fact/i
print("The sum of the series = ",sum)
n=int(input())
sum=0.0
fact=1
for i in range(1,n+1):
fact*=i
sum+=fact/i
print("The sum of the series = ",sum)
Input/Output:
Enter the range of number:
18
The sum of the series = 378011820620314.0
18
The sum of the series = 378011820620314.0
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box