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 plssss Optimize the equation P = 3x + y using the constraints x ≥ 0, x ≤ 4, y ≥-1 and y ≤ 5. What is the maximum?
STOP DELETING MY QUESTIONS BRAINLYPATROL THIS IS MATH 50,000 mm to yards round to nearest hundredths
Why is standard time considered necessary ?​
why was the early 20th century model of the atom flawed
write an email to your friend, to say thank you for your stay
I need help NOW asp please!!!!
Which of the following is NOT a cause of stress? Headaches Frustration Threat Hurt
(3.6 × 10-5) ÷ (1.8 × 103) Give your answer in standard form.
The volume of the given figure is __ ft3
6. Annie has a cube that has a side length of 9 cm. What is the surface area of the cube?​