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

Help????????? Surface area
A line segment is dilated by a factor of 4 and the center of the dilation is a point on the line segment. Which of the following is the result of this dilation?
Four unequal resistors are connected in series with each other. Which one of the following statements is correct about this combination?A. The equivalent resist
select all of the equations equivalent to 7x/3 = 14
What is the answer to this question I really don’t know this
What is the value of x? Enter your answer in the box.
Language spoken by educated Americans
Describe Purkinje Cells?
The plain stretches across northern India and is home to one-tenth of the world'a population
Bruce reads for 3/4 hour each night how long will he read in 4 nights​