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

Which is the site of the light-dependent reactions of photosynthesis?
HELP 20 POINTS || During REM sleep, ==> a) the level of stress in the body rises b) the brain prepares for daytime performance c) eye movement slows down d)
Extrinsic definition
One reason hunters migrated further south then settling in the northmost part of America
which of the following statements about minerals is false?
Discuss the role of cricket in Indian society,
Why did Athens have olive oil and wine to trade with other places?
The mining of oil shale requires ____. A) semi-arid conditions B) hot metal-rich fluids C) Pressurized steam D) large amounts of water
A store owner buys cell phones for $40 and a mark up the price by 25% explain how to find the price at which she sells the cell phone
A plumbing contractor bid the​ rough-in work for a new​ three-story office building based an estimate of 850 hours of a​ journey-level plumber's time on the job