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

Giving brainlist to whoever answers
Determine the mass of fuel required for the expected energy consumption in the United States for the next 10 years: Provide the energy use per person per year i
What is 1 plus 1 This is just a test because literally no one has been answering my questions. What is up with people and posting files
Identify which part of a circle the following is point B A Center Point B Point of Tangency С H Point D None of these options A F E
what’s does e equal?
Item 6 Worton Distributing expects its September sales to be 20% higher than its August sales of $168,000. Purchases were $118,000 in August and are expected to
3. A mutation is any change in the DNA sequence that leads to a disadvantageous outcome. • change in the DNA sequence. • change in the DNA sequence that leads t
6x - 5y = 11 y = 7x + 21 What is the correct answer to this problem?
Which expression is equivalent to 6 (3 + 4) ?
The Great Gatsby Chapter 5: What does this quote mean?