Examples of C part 66 sum of series 1^2-2^2........

Program :
#include <stdio.h>
 #include<math.h>
 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++)
   {
    if(i%2==0)
    {
     sum-=pow(i,2);
     }
     if(i%2==1)
     {
      sum+=pow(i,2);
     }

   }
   printf("Sum of series\n");
   for(i=1;i<=num;i++)
   {
    if(i!=num)
    {
     if(i%2==0)
     {
         printf("%d^2+ ",i);
      }
      else
      {
       printf("%d^2- ",i);
      }

     }
     else
     {
      printf("%d^2 = %d\n",i,sum);
     }

   }
 }
Output:
Enter number
6
Sum of series
1^2- 2^2+ 3^2- 4^2+ 5^2- 6^2 = -22
Explanation:
//Coming Soon...