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

'for a good cause if you are determined you are able to overcome any obstacle'. explain
What is a synonym for sensory language?A.simileB.fluencyC.metaphorD.imagery im thinkin D?
How many hours are 180 minutes
Where did the Greeks believe that most gods lived
Is the E-CIG industry more "safe" than the actual tobacco companies? Why? If someone offered you E-CIGS than cigarettes would you say yes or no? Why?Full Paragr
David helped his father stock the pond with baby catfish and blue gill. They put in a total of 75 fish. If the number of blue gill was doubled and the number of
Compute the value of the discriminant and give the number of real solutions to the quadratic equation: 3x^2 - 7x + 9 = 0
Compute the value of the discriminant and give the number of real solutions to the quadratic equation: 3x^2 - 7x + 9 = 0
Multiply these fractions (Lowest Terms) a) 2 x 3/4 b) 3 x 3/5 c) 4 x 1/3 d) 6 x 2/5 e) 1/2 x 1/4 f) 4/5 x 2/3 g) 5/6 x 3/4 h ) 1/10 x 2/3 i) 2 1/5 x 1/
Which expression can be used to change 75 kilometers per hour to meters per minute?