how to Write A Program TO PRINT THE SUM OF THE FOLLOWING SERIES
S=(1+2)/(1*2)+(1+2+3)/(1*2*3)+ - - - - - - UPTO N TERMS in java using bluej.
Answers
Answered by
7
Answer:
This is the required program for the question in Java.
import java.util.*;
public class Sum {
public static void main(String args[]) {
int n,i;
float s=0.0f,p=1.0f,q=1.0f;
Scanner sc=new Scanner(System.in);
System.out.print("Enter limit - ");
n=sc.nextInt();
sc.close();
for(i=2;i<=n+1;i++) {
q+=i;
p*=i;
s+=q/p;
}
System.out.println("Sum is: "+s);
}
}
Note: Here, p calculates the values of denominator part and q calculates the value of numerator part of each term in the series. Then, the value of q/p is added to the sum variable. The sum is displayed on the screen after calculation.
Refer to the attachment.
•••♪
Attachments:
Similar questions