Search:

Submit Article

# PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBOARD SUM =1+4-9+16-25+36-.....

Posted By: Adelbert Fischer     Category: C Programming     Views: 2203

## Code for PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBOARD SUM =1+4-9+16-25+36-..... in C Programming

```void main()
{
int n,i,sum=0;
clrscr();
printf("\n PLEASE ENTER THE VALUE OF N: ");
scanf("%d",&n);
printf("\n\n SUM = ");
for(i=1;i<=n;i++)
{
if(i%2==1)
{
if(i==1)
sum=1;
else
sum=sum-i*i;
if(i==n)
printf("%d",i*i);
else
printf("%d + ",i*i);
}
else
{
sum=sum+i*i;
if(i==n)
printf("%d",i*i);
else
printf("%d - ",i*i);
}
}
printf("\n THE SUM IS %d",sum);

getch();
}

*************************** OUTPUT ************************

PLEASE ENTER THE VALUE OF N: 6

SUM = 1 + 4 - 9 + 16 - 25 + 36
THE SUM IS 23

PLEASE ENTER THE VALUE OF N: 7

SUM = 1 + 4 - 9 + 16 - 25 + 36 - 49
THE SUM IS -26

***********************************************************```
Share:

 Adelbert Fischer author of PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBOARD SUM =1+4-9+16-25+36-..... is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!