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

how do I round 3.047 to the nearest hundred and show the math
how to Express each decimal as a fraction or a mixed number in a simplest form ? I need help with -0.14
1.133 g of silver nitrate was heated in an open tube. The silver residue weighed 0.720 g. During the reaction 0.307 g of nitrogen dioxide was also produced. Th
2h/3-1/4=1/3 solve and show your steps
List the perfect squares between 100 and 500 that are even numbers
List the perfect squares between 100 and 500 that are even numbers
What Was Jackson’s perspective on the McCulloch v. Maryland Supreme Court Case
placing 12 tiles side by side, Pete can make a 12-by-1 rectangle. Name two other rectangles Pete can make with 12 tiles
1.133 g of silver nitrate was heated in an open tube. The silver residue weighed 0.720 g. During the reaction 0.307 g of nitrogen dioxide was also produced. Th
What is an equivalent fraction for 20/12