C Program to Find out the Sum of Series 1^2 + 2^2 + … + n^2

C Program to Find Sum of the Series post providing implementation program to find the result of above series using C programming language.


C Program to Find  Sum of the Series

#include <stdio.h>
void main()
{
int number, i;
int sum = 0;

printf(“Enter max value of series number: “);
scanf(“%d”, &number);
sum = (number * (number + 1) * (2 * number + 1 )) / 6;
printf(“Sum of the given series : “);
for (i = 1; i <= number; i++)
{
if (i != number)
printf(“%d^2 + “, i);
else
printf(“%d^2 = %d “, i, sum);
}
}

Share this