Computer Science, asked by sheelags83, 6 months ago

write a java program to find the sum of the series given below, taking the values of a and n from the user.S=a/2+a/3+a/4+.............to n.​

Answers

Answered by SnehaKesharwani
3

Answer:

/**

* Program to

*

* Anirudh Gupta

* th August 2014

*/

import java.io.*;

public class Program87b

{

public static void main () throws IOException

{

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br= new BufferedReader(isr);

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

double a=Double.parseDouble(br.readLine());

System.out.println("Enter the limit for the denominator");

int limit=Integer.parseInt(br.readLine());

double n=1.0;

double sum=0.0;

while(n<=limit)

{

sum=+(a/n);

n++;

}

System.out.println(sum);

}

}

Hope it will help you...thank u

Answered by anindyaadhikari13
15

Question:-

Write a java program to find the sum of the series.

S=a/2+a/3+a/4+....+a/n

Program:-

Here is your program written in Java.

import java.util.*;

class SeriesSum

{

public static void main(String args[])

{

double s=0.0, x;

int n, a, i;

Scanner sc = new Scanner(System.in);

System.out.print("Enter the value of n: ");

n=sc.nextInt();

System.out.print("Enter the value of a: ");

a=sc.nextInt();

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

{

x=a/(double)(i+1);

s+=x;

}

System.out.println("Sum of the series is: "+s);

}

}

Similar questions