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 =12-32+52-72+.....

Posted By: Clara Shaw     Category: C Programming     Views: 2230

WRITE A PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES.
INPUT STEPS FROM KEYBORD.
SUM =12-32+52-72+.....

Code for PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBORD SUM =12-32+52-72+..... in C Programming

#include<stdio.h>
#include<conio.h>
    
void main()
{
    longint n,i,j,sum=0;
    clrscr();
    printf("\n PLEASE ENTER THE VALUE OF N: ");
    scanf("%ld",&n);
    printf("\n SUM = ");
    for(j=1,i=12;j<=n;i=i+20,j++)
    {
        if(j%2==1)
        {
            sum=sum+i;
            if(j==n)
            printf("%ld",i);
            else
            printf("%ld - ",i);
        }
        else
        {
            sum=sum-i;
            if(j==n)
            printf("%ld",i);
            else
            printf("%ld + ",i);
         }
     }
     printf("\n\n THE SUM IS %ld",sum);

     getch();
}


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

 PLEASE ENTER THE VALUE OF N: 9


 SUM = 12 - 32 + 52 - 72 + 92 - 112 + 132 - 152 + 172

 THE SUM IS 92


*********************************************************************
  
Share: 



Clara Shaw
Clara Shaw author of PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBORD SUM =12-32+52-72+..... is from Wichita , United States. Clara Shaw says

 
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!