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

when planning menu name and define 3 processes we establish after choosing menu items
List and define at least 4 different statistics demographers use to study population.
the bankruptcy of which company invited the panic of 1873
I need help on this question: A car has a velocity of 24 km/hr. The car stops. It takes the car 3 seconds to stop. What is the car’s acceleration?
A family of 8 mice move into your barn. After 3 months, there are now 51 mice. At 8 months, how many mice will you have in your barn?
It is reported that 32% of shoppers use cash to pay for their purchases. Based on this report, if a store has 250 sales in one day, how many shoppers could be
How does the moon change in the course of the story “Embers of moonlight”?
The central intelligence agency is an example of independent
Use the two patterns below add 5 5 10 15 add 3 3 6 9
I need to know the surface area.