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

Which student is most clearly determining new research goals
mr.ford select 2/5 of 120 people who tied out for theatrical production​
Witch of the following is not true about the theme A. A theme may be explicit or implicit B. There can be more than one theme in a narrative C. A theme is fo
How does the heart fit into the level of organization?
Can you balance this chemical equation?
Which of the following is one of the purposes of the Human Genome Project?
Given that sin0= 1/4,0 <0 < pi/2 , what is the exact value of cos 0 (picture provided)
Give collinear points in space, how many lines can be drawn
can someone plz help me wit #1??
how describe a shape of a graph