WAP in java to find the sum of the series x+(x^2/2)+(x^3/3)+(x^4/4).....(x^n/n)
Answers
Answered by
3
Answer:
import java.util.Scanner;
public class SeriesSum
{
public static double calcSeriesSum(int x, int n)
{
double i, total = 1.0;
for (i = 1; i <= n; i++)
{
total += (Math.pow(x, i) / i);
}
return total;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("ENTER A NUMBER: ");
int x =sc.nextInt();
System.out.print("ENTER THE NUMBER OF TIMES THE SERIES SHOULD BE EXECUTED: ");
int n = sc.nextInt();
System.out.printf("%.2f", calcSeriesSum(x, n));
}
}
Explanation:
Similar questions