Computer Science, asked by ayush3213, 11 months ago

write a program to compute and display the sum of the following series : S = 1 + 2 / 1* 2 + 1+2+3 / 1*2*3 + ...... + 1+2+3.......+n / 1*2*.......*n

Attachments:

Answers

Answered by anindyaadhikari13
3

Question:-

Write a program to compute and display the sum of the following series.

S=(1+2)/(1*2) +(1+2+3)/(1*2*3) +....

Program:-

import java.util.*;

class Sum

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value of n: ");

int n=sc.nextInt();

double a=0.0,b=1.0;

for(int i=2;i<=n;i++)

{

a+=i;

b*=i;

s+=a/b;

}

System.out.println("Sum of the series is: "+s);

}

}

Similar questions