Write a program to calculate and print the sum of each of the following series :
i. S=2-4+6-8+…………-20
ii. S=(1+2)/(1x2)+(1+2+3)/(1x2x3)+(1+2+3+4)/(1x2x3x4)+……. +(1+2+3+4…..n)/( 1x2x3x4x…..n)
Answers
Answered by
1
Answer:
//Program using switch case
import java.util.*;
public class Series
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int ch;
System.out.println("Enter 1 for sum of Series 1");
System.out.println("Enter 2 for sum of Series 2");
System.out.println("Enter your choice");
ch=in.nextInt();
switch(ch)
{
case 1:
int a,s=0;
for(a=2;a<=20;a=a+2);
{
if(a%2==0)
s=s-a;
else
s=s+a;
}
System.out.println("The sum of the given series="+s);
break;
case 2:
int n,b;
double sum=0.0
System.out.println"Enter n");
n=in.nextInt();
for(b=1;b<=n;b++)
{
sum=sum+(double)(b+(b+1))/(b*(b+1));
}
System.out.println("The sum of the given series="+sum);
break;
default:
System.out.println("Invalid choice");
}
}
}
Similar questions