write a java program to compute and print the sum of the following series S=x/2-x^2/4+x^3/6-x^4/8+...+x^n/2n
Answers
Answered by
0
Answer:
Program:-
import java.util.*;
public class Series
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int a,n,x;
double s=0.0;
System.out.println("Enter x");
x=in.nextInt();
System.out.println("Enter n");
n=in.nextInt();
for(a=1;a<=n;a++)
{
s=s+(double)(Math.pow(x,a)/2*a);
}
System.out.println("The sum of the given series="+s);
}
}
Similar questions