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

Is it safe to take Capsule lycored during pregnancy?
what is air currents caused by temperature differences
Help me plz! Which organism is the herbivore in this food web? A. leopard seal B. orca C. zooplankton D. cod
Which sentence is punctuated correctly? A. The three state capitals that I have visited are Austin; Texas, Montgomery; Alabama, and Bismarck; North Dakota. B. T
Members of which of the following phyla have the most species that parasitize humans? a.Porifera b.Mollusca c.Echinodermata d.Platyhelminthes
please help me on problem 2 of Solving Unit-Rate Problems
What effect does the simple, sing-songy meter have in "The Battle of Blenheim"? A. It inspires readers to recall important battles from history. B. It echoes th
Which phrase best describes the “cause” that Paine refers to
The condensation of _____ formed the early oceans. It is an important part of the water cycle.
Compare 0.35 and 7/20