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

Breastfeeding is better than formula because it leads to a lower incidence of        a. ear inflammation.        b. respiratory illness.      C.  allergies.
Atoms have a tendency to complete their outer energy level. This is known as _____. decomposition synthesis the octet rule the rule of electrons
What are 3 ways scientists get to the mantle of earth
-2x+y=10 4x-y=-14 solve substitution
One benefit of going to work instead of college after graduation is
What is a fact sheet?
The perimeter of a rectangle is 36 and the length is twice the width.What are the dimensions of this rectangle and what is the area?
Wich of the following is not a reptile? a. snake b. lizard c. aligator d. salamander
164 is 55% of what number? Please somebody help me
there are 54 students in the marching band. they for equal rows, so that there are no fewer than 5 rows and no more than 10 students in each row. how many rows