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

24x+2y=52 6x-3y=-36 How would I solve by elimination showing work
What material makes up earth's outer core
Describe the two types of ocean currents
Can you make a triangle with side lengths of 7, 8 , and 15? Explain
what physical map uses color to indicate elevation and features.
why do people stress
What is x2-5x+6=0 factorised?
Amalia uses two different dietary analysis software programs to determine the vitamin E content of a 1-oz serving of cooked asparagus. She notices the amounts g
I dont get this at all
Joe wants to earn more than $71