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

Which of the following is an antonym of the word happy? a. joyful b. jovial c. miserable d. blissful
What did the "rule of law" mean to the average, plebeian Roman.
Examples of this molecule include bread and rice
why would you share your wealth with the poor?
Is giving gifts the best way to sell something ?
how does maycomb react to the news if toms death
Why is Jing-mei able to get away with making a lot of mistakes on the piano? In "Two Kinds" by Amy Tan
which array represents 4x19?
Where should an object be placed in front of a concave mirror’s principal axis to form an image that is real, inverted, larger than the object, and farther from
It is impossible for a stable joint to become too mobile. true or false.