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

write 125 as the product of three factors and as a power of base 5​
The Supreme Court's decision in the case of McCulloch v. Maryland most closely lined up with the position of which of the following? A. Alexander Hamilton B. Th
Which relationship describes angles 1 and 2
Find the diameter in units.
Which of the following identifies root causes of problems and issues in an effective manner? A) Investigative questions B) Trial and error approach D) Force-fie
PLZ PLZ PLZ ANSWER QUICK Why might the Roman strategy of hiring mercenaries to fight German soldiers have failed?
Can anyone help me please
20 points!!! Hurry hurry hurry!! Distance between points
What is the magnitude and phase of X. [tex]X=\sqrt{3-4i}[/tex]
please help asap How does the number of chromosomes in a daughter cell compare to the number of chromosomes in a parent cell? Question options: The daughter cel