Find sum of series 1/2!+2/3!+3/5!+.....N/(N+1)!

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 ifa = 1;
  for (i = 1i <= numi++)
  {
    fa *= i;
  }
  return fa;
}
int main()
{
  int n;
  double sum = 0.0i;
  printf("Enter the range of number:");
  scanf("%d", &n);

  for (i = 1i <= ni++)
  {
    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++
  

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 ifa = 1;
    for (i = 1i <= numi++)
    {
        fa *= i;
    }
    return fa;
}
int main()
{
    int n;
    double sum = 0.0i;
    cout << "Enter the range of number:";
    cin >> n;

    for (i = 1i <= ni++)
    {
        sum += i / fact(i + 1);
    }

    cout << "The sum of the series = " << sum;
}


Input/Output:
Enter the range of number:8
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 ifa = 1;
        for (i = 1i <= numi++) {
            fa *= i;
        }
        return fa;
    }

    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);
        int ni;
        double sum = 0.0;
        System.out.println("Enter the range of number:");
        n = cs.nextInt();
        for (i = 1i <= ni++) {
            sum += (doublei / 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
  

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 = 1
sum = 0.0
while(i <= n):
    sum += float(i/fact(i+1))
    i += 1
print("The sum of the series = "sum)


Input/Output:
Enter the range of number(Limit):
3
The sum of the series =  0.9583333333333333


Post a Comment

0 Comments