write a program to print n terms of series 1, (1+2),(1+2+3),....
Answers
Answered by
8
⛤Hey There⛤
_____________________________________________
Write a program to print n terms of series 1, (1+2),(1+2+3),....
import java.util.*;
class 1855 {
// Function to find sum of given series
static int sumOfSeries(int n)
{
int sum = 0;
for (int i = 1 ; i <= n ; i++)
for (int j = 1 ; j <= i ; j++)
sum += j;
return sum;
}
/* Driver program to test above function */
public static void main(String[] args)
{
int n = 10;
System.out.println(thesumOfSeries(n));
}
}
_____________________________________________
Write a program to print n terms of series 1, (1+2),(1+2+3),....
import java.util.*;
class 1855 {
// Function to find sum of given series
static int sumOfSeries(int n)
{
int sum = 0;
for (int i = 1 ; i <= n ; i++)
for (int j = 1 ; j <= i ; j++)
sum += j;
return sum;
}
/* Driver program to test above function */
public static void main(String[] args)
{
int n = 10;
System.out.println(thesumOfSeries(n));
}
}
prathamesh1855:
Mark as brainliest
Answered by
0
Sum of the series S=1+(1+2)+(1+2+3)+(1+2+3+4)+….+(1+2+3+…+n) where the value of ‘n’ is given by the user.
Input : n = 5 Output : 35 Explanation : (1) + (1+2) + (1+2+3) + (1+2+3+4) + (1+2+3+4+5) = 35 Input : n = 10 Output : 220 Explanation : (1) + (1+2) + (1+2+3) + .... +(1+2+3+4+.....+10) = 220
Input : n = 5 Output : 35 Explanation : (1) + (1+2) + (1+2+3) + (1+2+3+4) + (1+2+3+4+5) = 35 Input : n = 10 Output : 220 Explanation : (1) + (1+2) + (1+2+3) + .... +(1+2+3+4+.....+10) = 220
Similar questions