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

Translate “the nurse” into Spanish
Given that a=4 and b=5. evaluate : a²+3b​
people with healthy media diets: A.do not have problems with addictions, obesity, or other health issues B. make good choices about what media to use and when n
HELP I GIVE 15 POINTS
What is being measured when counting the calories burned when resting?​
What is the measure of BAC. Degree of 53
What makes a pair linear?
3CuCl2 + 2Al => 3Cu + 2AlCl3
The respiration rate of a goldfish is measured. The goldfish is then placed in cold water and the respiration rate is measured again. What is the Independent
How does friction affect the motion of two objects sliding past each other