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 KEYBOARD SUM =1+4-9+16-25+36-.....

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

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

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
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 Comment

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

 
No Comment Found, Be the First to post comment!