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

how many molecules of oxygen is in water
From earth why dose the sun look so much larger than other stars ? Is the sun actually larger than the stars outside our solar system ? Explain your ideals belo
1.08 to the 3rd power?
A sentence that asks a question ends with a period. True False
What is this phrase in English? "Mi madre es muy inteligente."
What is this phrase in English? "Mi madre es muy inteligente."
g(x) = 4x+6 h(x)=x-5 Write the expressions for (g-h) (x) and (g-h) (x) and evaluate (g- h) (3). (g-h)(x) = (g-h)(x) = 0 (g+h)(3) =
Cuanto vale la y en matemáticas
A sentence that asks a question ends with a period. True False
Find the coordinates of the midpoint of the line segment with endpoints (6, -2) and (-3, -2). midpoint: (x, y) = ( )