Series 5

Series 5


1/2+2/3+3/4+4/5+..........upto n terms.

/* This is a fractional series where denominator=numerator+1 */

import java.io.*;

class Series7{

public static void main(String args[])throws IOException{

//declare all the variables at the beginning
int a,b,i;
float t,sum;

    BufferedReader br = new BufferedReader( 
                new InputStreamReader(System.in));
    System.out.println("Enter the number of terms : ");
        n=Integer.parseInt(br.readLine());

    //set the sum as 0 initially.
    sum=0.0f;

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

        a=i;

        b=i+1;

        t=(float)(a/b);     

        sum+=t;

        }//end of loop

        System.out.print("Sum = "+sum);

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

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

0 comments