Computer Science, asked by ranjitkumarmodi9634, 1 year ago

Write a program to find the sum of geometric series s=a + ar + ar^2 + ar^3 + .....+ n

Answers

Answered by kir2
0
import java.util.*;
public class series
{
public static void main (String args [ ])
{
Scanner in=new Scanner (System.in);
int p,a,n,i,r,s=0;
System.out.println ("Enter the value of a ,n and r");
a=in.nextInt ();
n=in.nextInt ();
r=in.nextInt ();
s=a;
for (i=1;i <=n;i++)
{
p=Math.pow (r,i);
s=s+(a*p);
}
System.out.println ("Sum of the series="+s);
}
}
Hope its helpful !!!!
Similar questions