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

3Which is largest in 6(2/3)%, 3/20and 0.14?​
What is the percent of increase from 20 to 37?
HELP PLEASE QUICKLY!! Please
from The Beast by Ben B. Lindsey and Harvey J. O’Higgins The chief effect of the imagery and figures of speech in paragraph 15 is to A. prolong the outcome of t
The overall reactions for photosynthesis and cellular respiration are opposite of each other. Select TWO (choose two!) statements that describe the two processe
If angle ABD equals 30 degrees, solve for x ?
Do you know why some people get sunburn on a cloudy day?
need rn! worth 30 What is the value of T(−4) when T(x)=−x−2?
Which of the following is not a potential result of a bottleneck event? a. an increase in potential mates b. a decrease in genetic diversity an increase in inbr
Which of the following is equal to [(x^2y^3)^-2/(x^6y^3z)^2]^-3