Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mathematics ProgramRSS Feeds

Program that uses while loop and calculate sum of every third integer number with i=2 (i.e. sum = 2+5+8+11+.) for values of I that is less than 100

Posted By: Angelo Smith     Category: C Programming     Views: 8880

Write a program using while loop that will calculate
the sum of every third integer beginning with i=2
(i.e. sum = 2+5+8+11+.)
for values of I that are less than 100.

Code for Program that uses while loop and calculate sum of every third integer number with i=2 (i.e. sum = 2+5+8+11+.) for values of I that is less than 100 in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
        int i,sum=0,n=100;
        clrscr();
        printf("\n\n THE SERIES IS UNDER : \n\n\n");
        i=2;
        while(i<=n)
        {
            sum=sum+i;
            if(i==2)
                printf("%d",i);
            else
                printf(" + %d",i);
            i=i+3;
        }
        printf("\n\n\n THE SUMMATION IS %d",sum);
        getch();
}    


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

     THE SERIES IS UNDER :

    2 + 5 + 8 + 11 + 14 + 17 + 20 + 23 + 26 + 29 + 32 + 35 + 38 + 41 + 44 + 47 + 50
    + 53 + 56 + 59 + 62 + 65 + 68 + 71 + 74 + 77 + 80 + 83 + 86 + 89 + 92 + 95 + 98

         THE SUMMATION IS 1650

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



Angelo Smith
Angelo Smith author of Program that uses while loop and calculate sum of every third integer number with i=2 (i.e. sum = 2+5+8+11+.) for values of I that is less than 100 is from Sydney, Australia.
 
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!