Problem Statement:- Program to find the sum of series 1/2!+2/3!+3/5!+4/6!+.....N/(N+1)!.
Data requirement:-
Input Data:- n
Output Data:-Sum
Additional Data :-i,fact,fa,num
Program in C
Here is the source code of the C Program to find the sum of series 1/2!+2/3!+3/5!+ 4/6!+.....N/(N+1)!.
Code:
#include <stdio.h>/* this Function is Calculating Factorial of the Number */int fact(int num){int i, fa = 1;for (i = 1; i <= num; i++){fa *= i;}return fa;}int main(){int n;double sum = 0.0, i;printf("Enter the range of number:");scanf("%d", &n);for (i = 1; i <= n; i++){sum += i / fact(i + 1);}printf("The sum of the series = %0.2lf", sum);}
Input/Output:
Enter the range of number:3
The sum of the series = 0.96
Program in C++
The sum of the series = 0.96
Program in C++
Here is the source code of the C++ Program to find the sum of series 1/2!+2/3!+3/5!+ 4/6!+.....N/(N+1)!.
Code:
#include <iostream>using namespace std;/* this Function is Calculating Factorial of the Number */int fact(int num){ int i, fa = 1; for (i = 1; i <= num; i++) { fa *= i; } return fa;}int main(){ int n; double sum = 0.0, i; cout << "Enter the range of number:"; cin >> n;
for (i = 1; i <= n; i++) { sum += i / fact(i + 1); }
cout << "The sum of the series = " << sum;}
#include <iostream>using namespace std;/* this Function is Calculating Factorial of the Number */int fact(int num){ int i, fa = 1; for (i = 1; i <= num; i++) { fa *= i; } return fa;}int main(){ int n; double sum = 0.0, i; cout << "Enter the range of number:"; cin >> n;
for (i = 1; i <= n; i++) { sum += i / fact(i + 1); }
cout << "The sum of the series = " << sum;}
Enter the range of number:8
The sum of the series = 0.999997
Program in Java
The sum of the series = 0.999997
Program in Java
Here is the source code of the C Program to find the sum of series 1/2!+2/3!+3/5!+ 4/6!+.....N/(N+1)!.
Code:
import java.util.Scanner;
/* this Function is Calculating Factorial of the Number */public class SumOfSeries { static int fact(int num) { int i, fa = 1; for (i = 1; i <= num; i++) { fa *= i; } return fa; }
public static void main(String[] args) { Scanner cs = new Scanner(System.in); int n, i; double sum = 0.0; System.out.println("Enter the range of number:"); n = cs.nextInt(); for (i = 1; i <= n; i++) { sum += (double) i / fact(i + 1); } System.out.println("The sum of the series = " + sum); cs.close(); }
}
import java.util.Scanner;
/* this Function is Calculating Factorial of the Number */public class SumOfSeries { static int fact(int num) { int i, fa = 1; for (i = 1; i <= num; i++) { fa *= i; } return fa; }
public static void main(String[] args) { Scanner cs = new Scanner(System.in); int n, i; double sum = 0.0; System.out.println("Enter the range of number:"); n = cs.nextInt(); for (i = 1; i <= n; i++) { sum += (double) i / fact(i + 1); } System.out.println("The sum of the series = " + sum); cs.close(); }
}
Input/Output:
Enter the range of number:
12
The sum of the series = 1.0000000041233323
Program in Python
12
The sum of the series = 1.0000000041233323
Program in Python
Here is the source code of the Python Program to find the sum of series 1/2!+2/3!+3/5!+ 4/6!+.....N/(N+1)!.
Code:
def fact(num): i = 1 fa = 1 while(i <= num): fa *= i i += 1 return fa
n = int(input("Enter the range of number(Limit):"))i = 1sum = 0.0while(i <= n): sum += float(i/fact(i+1)) i += 1print("The sum of the series = ", sum)
def fact(num): i = 1 fa = 1 while(i <= num): fa *= i i += 1 return fa
n = int(input("Enter the range of number(Limit):"))i = 1sum = 0.0while(i <= n): sum += float(i/fact(i+1)) i += 1print("The sum of the series = ", sum)
Input/Output:
Enter the range of number(Limit):
3
The sum of the series = 0.9583333333333333
3
The sum of the series = 0.9583333333333333
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box