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

What is the change in number of individuals in a population over time? A. population decrease B. population stability C. population growth D. population resista
The neolithic revolution is most closely associated with....
Two 1 litre jugs are each filled with a mixture of olive oil and vinegar. The first jug has 3 times as much as oil as vinegar and the second jug has 4 times as
How do u write 6 more the 7 times a number is 41 in algebraic equation??
Please tell me five slogans on conservation of natural vegetation.
Which of the following rivers is the world's busiest waterway ?
The base of right prism is rhombus of diagonal is 6 and 8cm and altitude is 12 cm find total surface area
The dimensions of a brick that weighs 25 N are 0.19 m × 0.07 m × 0.095 m. What pressure does the brick exert on the ground if it is resting on its largest face?
The neolithic revolution is most closely associated with....
other name for blood