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

Obi speaks very quietly during his speech, and he tends to mumble. Obi’s audience has trouble hearing him because he is not speaking very clearly. This is an ex
which is not a drawback to obtaining energy resources from the ocean floor
If f(x) = x2 +1 and g(x) = 3x+1, find g(20) + f(6).
Tamara's Truck Rental rents small "box" trucks to college students to move items from their parent's home to a campus apartment. The Rent Expense for a 12-foot-
Solve a/-6 + 8 = 12. a = a0
The ________ is a traditional measure of investigative effectiveness that compares the number of crimes reported or discovered to the number of crimes solved th
the perimeter of a frame is 24 inches.The width is 5 inches. What is the length
Anthropologist Carol Stack studied an impoverished urban African American community called the Flats in a town outside Chicago in the early 1970s. Identify the
How is 51.7 written in words
Factor the polynomial: x(3x + 5) - 4(3x + 5)