To find the series X=1+(1*2)+(1*2*3)+(1*2*3*4)+(1*2*3*4*5)+………n


//Write a program in Java to find the sum of the series  X=1+(1*2)+(1*2*3)+(1*2*3*4)+(1*2*3*4*5)+………n

public class ss
{
public static void main(String arg[])
{
int a,x,p;
x=0;
p=1;
for(a=1;a<=5;a++)
{
p=p*a;
x=x+p;
}
System.out.println(“The sum of the series is:”+x);

}
}

output :

 

 

 

 

 

 

In this program output is depend on the loop if you end the loop 10 this show first ans :4037913

if end the loop 5 then output is:153

if end with 3 then output is : 9

Try  it yourself

Related Posts

Comments are closed.