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

Brita withdrew $225 from her bank account.After her withdrawal,there was $548 left in brita's account. How much money did Brita have in her account before the w
what was life like on Earth for most of its history,
Simplify the expression below 5+3*2-4^2*|-2| A) 43 B) 48 C)-16 D)-21
Is 12 ounces and 355 milliliters nearly equivalent
Despite having the second largest economy in the world (after the United States) what problem faces Japan that could affect its economic growth? A) It does not
what's the answer to 27/3 - 40/8?
One way the modern atomic model differs from Thomson's atomic model is that electrons are no longer scattered throughout and atom's positive matter like chocola
HELP PLEASE Which equation is graphed here? A. y-3=-2/3(x+1) B. y-4=-3/2(x+2) C. y-1=-3/2(x+3) D. y+1=-2/3(x+3)
what is equal to 2/3
\log_{4} x + \log_{4} (x+5) = 6