write a program to compile the sum of the first n terms of the following series s=1-2+3-4+5-6.....
//write a program to compile the sum of the first n terms of the following series s=1-2+3-4+5-6.....
#include <stdio.h>
int main()
{
int n;
int sum=0,i;
printf("Enter the range of number.");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
sum-=i;
else
sum+=i;
}
printf("The sum of the series=%d",sum);
}
Comments
Post a Comment