C Programming Tutorial

 
 
 
 
void main()
{
    long int 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



*********************************************************************