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 real world situation that could be modeled by the equation 120 + 25x = 45x
how does noise affects the credibility of a text?
How do you find the square root of 50?
como puedo ponerle un mural de poemas ??????
what religious group comprises almost 90% of the iranian population? a.sunni muslums b.coptic christians c.shia muslums d.secular turks
which of the following best describes the relationship between the structure of the cell membrane and its function?
when is it appropriate to use acronyms and emoticons in business communication?
warm colors in a painting give it a cool,calm, or sad mood. true or false
Whats the color of lobsters blood
why do people believe some theories even if they are not supported by credible evidence?