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

people experience thinking as a kind of or ​
Use the given word as noun and verb in your own sentences ' Love '​
The graph shows a line of best fit for data collected on the number of inches Stephen grew during each year between the ages of 1 and 10. The equation for the l
By which process do plants obtain carbon from the atmosphere? photosynthesis cellular respiration decomposition consumption.
The length of a rectangle is 2cm less than twice the width. If y represents the width, state the inequality that the area of a rectangle is at least 15cm^2
the magnolia is both the state tree and state flower of which state?
80 of ___games is 32 games
At a local print shop, 4 copies can be made for $2. At this rate, how much would it cost to make 28 copies?
In this activity, you will write about an illness or injury you had for which you needed to visit the doctor. Use the past tenses (imperfecto and pretérito) in
Help, please! I'm rush rn and I want to make sure that my answers are correct so please answer thisss I hope there is an user that understands my situation rn​4