Swsan7715 Swsan7715
  • 03-06-2021
  • Computers and Technology
contestada

2- Write aC+ program that calculates the sum of all even numbers from [1000,2000], using the while loop.

Respuesta :

tonb
tonb tonb
  • 03-06-2021

Answer:

#include <iostream>

using namespace std;

int main() {  

 int n = 1000;

 int sum = 0;

 while(n <= 2000) {

   sum += n;

   n += 2;

 }

 cout << "sum of even numbers in [1000..2000] = " << sum << endl;

}

Explanation:

This will output:

sum of even numbers in [1000..2000] = 751500

Answer Link

Otras preguntas

based on the evidence provided, readers can conclude that trey is
Read the excerpt below from "Letter from Birmingham Jail" and then answer the question below: "My citing the creation of tension as part of the work of the nonv
Please help, 40 points.
Please I need help on this
plz help me im just stupid
Which Civil Rights Act banned discrimination against any person based on race or color? Question 7 options: 14th Amendment 15th Amendment Civil Rights Act of 19
You wanted to draw an enlargement of design that printed on a card that is 4 in by 5
Explain why you would or would not have a LASIK surgery if you wore contacts or glasses.Describe how public opinions related to this surgery have changed over t
PLEASE HELP. I'm confused on this could anyone help me and show me what I need to do to solve it.
You have 17 cats that live in houses on your street, 24 dogs, 3 fish, and 4 hamsters. What percent of animals on your block are dogs?