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

According to Islamic belief, Muhammad was the: First prophet Middle prophet 3rd prophet from Moses Final prophet
A scientist is observing an organism under the microscope. The organism was found in salt water, is multicellular, and its cells do not have nuclei. What is m
Students who major in science- or math-related fields would be eligible for the _____ grant
Describe the best teacher you ever had and what made them a great educator. Responses should be less than 150 words.
Parents who spend a great deal of time and money trying to find the best school for their children believe in the importance of:
Why are some examples of hitler's growing military agression in the late 1920's?
What two areas of the world has the most acts of genocide during the 20th century?
find the graph y=-1/2x-3
write a pseudocode statement that subtracts the variable downpayment from the variable total and assigns the result to the variable due.
Which group launched a successful boycott against california grape growers?