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

Stupas were best described as what
According to the geological time scale, in what era did most types of animals first appear? -Haden -Paleozoic -Mesozoic -Cenozoic
the length of a rectangle is 4 units greater than its width, and the area of the rectangle can be expressed by the equation y=x2+4x. what is a reasonable domain
What impact did the Vietnam war have on the American people? A. Americans would be hesitant to use military force overseas in the future B. America
Develop an argument, as the ruler of Babylon, defending the treatment of the Hebrews
where might a pronoun’s antecedent appear?
If the germs in a vaccine we're not dead or deactivated then the vaccine would
What was the jizya in the islamic empire?
Which of the following factors is not a concern of regional planning organizations? A. Economic development B. Land use C. Global trade agreements D. Waste mana
Which describes a reason fifteenth-century Europeans wanted to find a sea passage to East Asia?