S=1+(1+2)+(1+2+3)+.....+(1+2+3+........+n)
Answers
Here is the code of the program
_____________________________________
Code
import java.util.*;
class series_sum
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of the last term");
int n=sc.nextInt();
int s=0;
int sum;
for(int i=1;i<=n;i++)
{
sum=0;
for(int j=1;j<=i;j++)
{
sum=sum+j;
}
s=s+sum;
}
System.out.println("Sum="+s);
}
}
___________________________________________________
Sample input :
2
Output :
4
Working
S=1+1+2
= 2+2
=4
Hence output is 4.
______________________________________________________
Hope it helps you
_____________________________________________________________________