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

Is it safe to take Capsule lycored during pregnancy?
explain how fractions an decimals are related
The joining of nuclei and chromosomes is known as
how is a new cell resulting from mitosis like the original
Where should you look to quickly find factual information on the causes of the American Civil War? A. Readers' Guide B. Encyclopedia C. Concise Dictionary o
How are evaporation and transpiration similar? a They are both processes in which water is changed into water vapor. b Both processes occur immediately before p
how is a highway similar to transport systems of the body?
The ratio of boys to girls in a kindergarten is 2:3. If the number of boys is 12, find the number of girls.
raise 2/7 to a fraction with denominator of 28.
in a photo a man is 1.5 inches in height. if the man was 6 feet tall what is the scale