Computer Science, asked by amanakutty, 7 months ago

write a programme in Java to find the sum of series 1/x+1/x^2+1/x^3+......+1/x^n​

Answers

Answered by anindyaadhikari13
2

\star\:\:\:\sf\large\underline\blue{Question:-}

Write a program in Java to find the sum of the given series.

 \sf \frac{1}{x}  +  \frac{1}{ {x}^{2} }  +  \frac{1}{ {x}^{3} }  + .... +  \frac{1}{ {x}^{n} }

\star\:\:\:\sf\large\underline\blue{Solution:-}

import java.util.*;

class SeriesSum

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

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

int n=sc.nextInt();

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

double x=sc.nextDouble();

double s=0.0;

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

{

s=s+1/Math.pow(x, i);

}

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

}

}

Similar questions