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

What is the value of x?
Please help as soon as you can :)
school with 500 students has 30 math teachers. How many math teachers are needed for 750 students?
Why is the consumption of fruits and vegetables important?
-2x+3y-5x-(-8y)+9y= please help me
"Princess Tower" in Dubai is considered the world's tallest residential building, towering to 101 floors! T(N) models the number of tenants living on floor N of
Chest compressions should be initiated
(NEED HELP ASAP! PICS INCLUDED) What are the correct labels for this diagram of glucose catabolism? a. glycolysis b. 2 ATP c. ETS d. 34 ATP a. glycolysis b. py
Someone seeks buy-in from individuals, wants minimal risks, and tends to avoid interpersonal confrontation when it comes to decision would best be described as
need help badly. been stuck on this for 20 mins.