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

show that cos165 + sin165 = cos135​
Find the error with subject-verb agreement. Select the incorrect verb and type it correctly. Dominic's short story describe the adventures of a fictional ninete
Lucy is organizing slides in her research presentation on the effects of captivity on orcas. What should be on the first slide of her presentation? the works ci
Deku to bakugo o shinpu suru hito
Advise on the purchasing procedure
Please help! Will mark brainliest! Bill flips a coin and rolls a number cube. Create a list to show the sample space of the different outcomes.
Can someone please help me with part B? Thanks! I will give brainliest what the top says if you can’t see: “ A farm stand sells small, medium,and large pumpki
Please look at picture and ignore selected answers
what is meant by index of an element?​
The floor of a ballroom has an area of 2,470 square feet. If the length of the floor is 65 feet, what is its width?