Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

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

Posted By: Kelsey Reed     Category: C Programming     Views: 3270

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

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

#include<stdio.h>
#includde<conio.h>    

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: 



Kelsey Reed
Kelsey Reed author of PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBORD SUM =1+4-9+16-25+36-..... is from Los Angeles, United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!