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: