Answer to Question #130544 in C++ for Zaib Mk

Question #130544
Develop a program that will calculate the sum of every third integer beginning with i=2 calculate (i-e calculate the sum of series 2+5+8+…………) for all values of i that are less than 100?

Write the loop each of the following ways
a) Using for loop
b) Using do-while loop
c) Using while loop
1
Expert's answer
2020-08-26T01:39:15-0400
#include <iostream>


int main()
{
    int sum = 0;
    for(int i = 2; i < 100; i += 3)
    {
        sum += i;
    }
    std::cout << "Sum is " << sum;
    return 0;

}


#include <iostream>


int main()
{
    int i = 2;
    int sum = 0;
    while(i < 100)
    {
        sum += i;
        i += 3;
    }
    std::cout << "Sum is " << sum;
    return 0;

}


#include <iostream>


int main()
{
    int i = 2;
    int sum = 0;
    do
    {
        sum += i;
        i += 3;
    } while(i < 100);
    std::cout << "Sum is " << sum;
    return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS