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

PLEASE HELP I GIVE THANKS
How has water influenced the development of civilization in Africa
The Earth has four main seasons: winter, spring, summer, and fall. Which of the following is a cause of seasonal changes on Earth? The Earth rotates. The
What is the diameter of a circle whose circumference measures 86 26/35? Use pi= 22/7
according to the United States constitution the president has the power to (A) negotiate treaties (B) amend the constitution (C) impeach members of congress
The rectangle has an area of 4(x+3) square units. A- If the dimensions of the rectangle are doubled, what is the area of the new rectangle in terms of x? Show y
a antonym for biosphere
Please help solve, thanks in advance!
when Jefferson took office he did what
Which statement accurately describes the significance of the Magna Carta? A. It gave absolute power to the English king over the church and nobility. B.