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

(THIS MY FINAL DAY AT SCHOOL SO I NEED HELP)
The woman who opened the first birth-control clinic in the united states was lucretia mott. margaret sanger. susan b. anthony. emma hart willard.
Is it ethical for Mr. Thorne to kill his adopted son?
If 2x⁴,2y⁴,2z⁴=144,then find the mean of x⁴,y⁴,z⁴.
why did western europe economies grow faster that eastern european econemies after world war 2
Genetic engineering is also known as
4. The desire to renegotiate treaties with Western nations, such as the United States, demonstrates that Japan 1. sought to avoid European spheres of influence
make r the subject of the formula in V= ⅓π r²h​
A sample of cobalt has a mass of 27 g and a density of 9 g/cm^3. What would be its volume?
a negative number raised to an odd power is ____ negative ?