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

HELP ME PLEASE, I will help you too
How much energy is released when 22.4g of CH4 is burned?
What is morale? apparently the question was too short so this is filler
A circle has 9 times the area of another circle. If the radius of the larger circle is 27 meters, find the radius of the smaller circle.
PLEASE HELP! I’ll GIVE THE BRAINLIEST TO WHOEVER ANSWERS CORRECTLY!!
The 5-lb collar is released from rest at A and travels along the frictionless guide. Determine the speed of the collar when it strikes the stop B. The spring ha
PLZ HELP MEEEE GUYSS! ILL GIVE BRAINLIEST TO THE PROPER ANSWER PLS! What are 5 ways carbon dioxide is released into the environment? What is the role of decompo
helpp pt.4 plzzzzzz​
carousel______Nobelmen
Eight children plan to share 10 pounds of chocolate chips to make cookies. How many pounds of chocolate chips will each child get? Represent your answer as a