#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
int sum=0;
clrscr();
printf("\n enter the number n");
scanf("\n %d",&n);
sum=(n*(n+1)*(2*n+1))/6;
printf("\n sum of series =");
for(i=1;i<=n;i++)
{
if(i!=n)
{
printf(" %d^2",i);
}
else
{
printf(" %d^2=%d",i,sum);
}
}
return(0);
}
output:-
enter the number n=5
sum of series =1^2+2^2+3^2+4^2+5^2=55