/* 1-3+5-7+9-11
..... */
#include<stdio.h>
#include<conio.h>
void main()
{
int i, n, sum=0,k=-1;
clrscr();
printf("\n Enter the no.of terms: ");
scanf("%d",&n);
for(i=1;i<=2*n;i=i+2)
{
k=-k;
sum= sum + (k*i);
}
printf("\n Sum of %d terms: %d", n, sum);
getch();
}
No comments:
Post a Comment