Computer Science, asked by nimrakaleem, 4 months ago

WAP to find the sum of the series S=1-x^2/2!+×^4/4!-.......upto the nth term in java​

Answers

Answered by kamalrajatjoshi94
2

Answer:

import java.util.*;

public class Series

{

public static void main(String args[ ])

{

Scanner in=new Scanner(System.in);

int a,n,f=1,s=0,x;

double d=0.0;

System.out.println("Enter the number");

n=in.nextInt();

System.out.println("Enter the value of x");

x=in.nextInt();

System.out.println("The Series");

for(a=1;a<=n;a++)

{

if(f%2==0)

f=f*a;

f=f+2;

if(a%2==0)

s=s-(Math.pow(x,d))/f;

else

s=s+(Math.pow(x,d))/f;

d=d+2;

}

System.out.print("The sum of the series="+s)

}

}

Similar questions