Computer Science, asked by prottoykundu2006, 6 months ago

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 niteshkuriyal68
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