WAP in java to print the sum of the series s=(1/a)+(1/a^2)+(1/a^3)...........(1/a^n)
Answers
Answered by
2
import java.util.*;
class Series
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
double s=0.0d;
int a,n;
System.out.println("Enter value of a");
a=sc.nextInt();
System.out.println("Enter value of n");
n=sc.nextInt();
for(int i=1;i<=n;i++);
{
s=s+1/(Math.pow(a,i);
}
System.out.println("Sum="+s);
}
}
Similar questions
English,
3 months ago
Math,
3 months ago
Physics,
6 months ago
Social Sciences,
11 months ago
Social Sciences,
11 months ago