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 average elevation of the city of new orleans louisiana is 0.5 m below sea level the highedt point in louisiana is driskill mountain at about 163.5 m higher
How do i work this problem y= -3x - 5
write 0.941 with word name
Why might a scientist need to repeat an experiment
why do you suppose the population of deer declined in 1925, although the elimination of predators?
Because of Medicaid and Medicare, whose administration was seen as making great strides in health care? Answer John F Kennedy Richard M Nixon Lyndon B Johnson n
How did political debate in America change inthe years after 1774?
Round 6,529 to the nearest thousands
You are the sports looking to buy some new equipment for the sport or fitness activity your choosing. What should you keep in mind while choosing your gear
what is 100,000 less than five hundred sixty thousand , three hundred thirteen is