C program to Print Series 1^2+2^2+3^2+......n^2

#include <stdio.h>
#include<math.h>
int main()
{
 //1^2+2^2+3^2+......n^2
  int i,num,sum=0;
  printf("Enter number \n");
  scanf("%d",&num);
  for(i=1;i<=num;i++)
  {
   sum+=pow(i,2);
  }
  printf("Sum of series\n");
  for(i=1;i<=num;i++)
  {
   if(i!=num)
  {
      printf("%d^2+ ",i);
    }
    else
    {
     printf("%d^2 = %d\n",i,sum);
    }

  }
  return 0;
}
Output:





Previous Post Next Post