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

You disassemble and reassemble a desktop computer. when you first turn it on, you see no lights and hear no sounds. nothing appears on the monitor screen. what
A square is ____ a parallelogram. always sometimes never submit
The law of __________ states that traits are passed from parents to offspring independently of one another.
HELP PLEASE! −3.64⋅|−5.3|−1.53 ^ Absolute value of -5.3
These are the first sentences in the short story, “the gift of magi” by O. Henry: “one dollar ad eighty/seven cents. That was all. And sixty cents of it was in
What has research determined about the orbit of an electron around a nucleus
Help.................
weakly foliated, coarse-grained metamorphic rock that is made mostly of quartz and feldspar is _____. A. skarn B. gneiss C. phyllite D. quartzite
Plasmodium is a parasitic apicomplexan that causes malaria in humans. the figure below illustrates the plasmodium life cycle.
Excluding the Soviet Union, list the Asian countries in the communist bloc