Skip to content

p052.c

Problem Statement

Print the sum of this series for upto n element. Series: 1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3 + 4) + ... + (1 + 2 + 3 + ... + n)

Metadata

Property Detail
Author Amit Dutta (amitdutta4255@gmail.com)
License MIT

Actions

Raw View on GitHub

💡 You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>

int main()
{
    int n, sum = 0, temp = 0, i;
    printf("Enter the n : ");
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        temp += i;
        sum += temp;
    }
    printf("%d", sum);
    return 0;
}