Thursday, 16 November 2017

C Program to find the sum of series 1^2 + 2^2 + …. + n^2.


Code:

#include   stdio.h

int main()
{
    int number, i;
    int sum = 0;

    printf("Enter maximum values of series number: ");
    scanf("%d", &number);
    sum = (number * (number + 1) * (2 * number + 1 )) / 6;
    printf("Sum of the above given series : ");
    for (i = 1; i <= number; i++)
    {
        if (i != number)
            printf("%d^2 + ", i);
        else
            printf("%d^2 = %d ", i, sum);
    }
    return 0;
}

Output:

Enter maximum values of series number: 4
Sum of the above given series : 1^2 + 2^2 + 3^2 + 4^2 = 30


More C Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...