Series 20

Series 20


1+x^2/2!+x^4/4!+x^6/6!+x^8/8!+..........upto n terms.

import java.util.*;

 class Series22
 {
public static void main(String args[])
throws InputMismatchException{
Scanner scan=new Scanner(System.in);

System.out.println("Enter the limit: ");
int n = scan.nextInt();

System.out.println("Enter a value for x: ");
int x = scan.nextInt();

int i, j, f, p=0;
double t, s=0.0;

for(i=1;i <= n; i++){

    f = 1;
    for(j=1;j<=p;j++)
        f = f*j;

    t = Math.pow(x,p)/f;

    s = s + t;
    p = p + 2;
}

System.out.println("Sum = "+s);

}//end of main
}//end of class

Have something to say? Log in to comment on this post.

0 comments