A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to calculate the sum of the series 1+(1+2) +(1+2+3) +(1+2+3+4) +...+(1+2+3+...+n)
Q:

C program to calculate the sum of the series 1+(1+2) +(1+2+3) +(1+2+3+4) +...+(1+2+3+...+n)

0

C program to calculate the sum of the series 1+(1+2) +(1+2+3) +(1+2+3+4) +...+(1+2+3+...+n)

The series is: 1+(1+2) +(1+2+3) +(1+2+3+4) + ... +(1+2+3+...+n), we have to find out the sum up to N terms.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

We know the sum of natural numbers up to n = (n(n-1))/2

If we simplify this we get, n(n+1)(2n+4)/12

If we put the number of terms in the above equation then we'll get the sum of the series up to that particular term.

Now, let's see Program it using the using c program,

#include <stdio.h>

//function for creating the sum of the
//series up to Nth term

int series_sum(int n)
{
    return ((n * (n + 1) * (2 * n + 4)) / 12);
}

int main()
{
    int n;
    
    printf("Series:1+(1+2+)+(1+2+3)+...+(1+2+3+...+n)\n");
    printf("Want some up to N terms?\nEnter the N term:");
    scanf("%d", &n);

    printf("Sum is:%d", series_sum(n));

    return 0;
}

Output

Series:1+(1+2+)+(1+2+3)+...+(1+2+3+...+n)
Want some up to N terms?
Enter the N term:10
Sum is:220

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now