Series 12

Series 12


x/2 + x/5 + x/8 + x/11 + ..........upto n terms.

import java.util.*;

 class Series14
 {
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,  a=2;
double b, s=0.0;

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

    b = (double)x/a;
    a = a + 3;
    s = s + b; 
}

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

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

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

0 comments