WAP in C program to find the sum of series 1^2 + 2^2 + 3^3 …. + n^2.

// Copy the following code and compile it to find the sum of the squares if numbers up to nth terms 

#include<stdio.h>


int main()
{


  int n,j;

  int s=0;


  printf("Enter the value of n");

  scanf("%d",&n);


  s = (n*(n+1)*(2*n+1))/6;


  printf("Sum of the series is : ");
 
  for(j =1;j<=n;j++)
  {

     if (j!= n)

        printf("%d^2 + ",j);

     else

       printf("%d^2 = %d ",j,sum);

  }


 return 0;

}

Comments