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

Please can anyone help me out?? :(
Which of the following equations is equivalent to 4x -y=3`?
HELP ASAP ILL GIVE BRAINLIEST!
How many significant figures are in this number? 3 x 10^6
Which of the following phrases describe the functions of the digestive system? I. Smooth, muscular tube connects the mouth to the stomach II. Muscular action
Pls help me ASAP I have other homework to do and I don’t have time for this. It also detects if it’s right or wrong:(
In 8 divided by 1/5 the number 8 is the?
Different classes of stocks are usually issued in order to Group of answer choices maintain ownership control, by holding the class of stock with greater voting
efwrvrvrv3rvrvb3rvr3vrvrv
Diversidad de los espacios geográficos rurales​