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

The ability of African Americans to vote was constrained by:
In our own nation, the Boston Tea Party represented a massive act of civil disobedience. Why does King use this allusion? to establish historical precedent for
What this cell type
2Plss solve for x.........
Son obras realistas, EXCEPTO: Seleccione una: a. Recuerdos de la casa de los muertos b. Pobres gentes c. Eugenia Grandet d. Madame Bovary e. Torcuato Tasso
Preface to Buddhism and Buddhists in China Which phrase best describes the tone of this passage? Enthusiastic but skeptical Matter-of-fact but impressed Neut
which of the following is an example of operant conditioning?
The correct value according to Ruler A is 2.2 cm c m , whereas the correct value according to Ruler B is 2.27 cm c m . Perform the mathematical operations indic
Hshshdh pls awnser as soon as possible
See question in attached photo.​