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

According to Biden, what does he need to control before America can go back to normal​
Luna Park in Coney Island charges $12 for entry and $2 per ride. Ariana visits the park and goes on 4 rides. How much money did she spend in total?
Which of these is a geometric sequence? 2,3,5,9,17
"Rule of law" refers to the (4 points) Group of answer choices official name for the legislative branch of the national government of the United States agencies
the ratio of the heights 1.50 cm and 75 cm of two person can be written as​
At time t = 0.00 s, a car is traveling along a straight line at a speed of 10 m/s with constant acceleration. The car travels 46.0 m during the time interval be
Did Albert Einstein try to measure the speed of light in the early 1600s?
f(x) = 2x - 4 f(3) = [?]
Why is the red stuff coming out my underwear place pleaseeee helpp
3) Movement of water through the oceanic benthic zone. 10 p A. Intertidal Zone B. Tides C. Deep Currents D. Surface Currents E. Waves 4) Area between high- and