1. Write a program to find the sum of the following series:
S=1+(1+2) + (1+2+3) + (1+2+3+4) + (1+2+3+4+5) +…+(1+2+3+4+…+10) (ezie)
Answers
Answer:
answer
public class KboatSeriesSum
{
public static void main(String args[]) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
int p = 1;
for (int j = 1; j <= i; j++)
p *= j;
sum += p;
}
System.out.println("Sum = " + sum);
}
}
Here's a program in Python to find the sum of the given series:
# Define a function to calculate the sum of the series
def series_sum(n):
# Initialize the sum to 0
s = 0
# Loop over each term in the series
for i in range(1, n+1):
# Calculate the sum of integers from 1 to i
term_sum = sum(range(1, i+1))
# Add the term sum to the overall sum
s += term_sum
# Return the final sum
return s
# Call the function with n=10 to calculate the sum of the series
result = series_sum(10)
# Print the result
print(result)
Output:
220
So the sum of the given series is 220.