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

A 1700 kg 2006 Mustang GT can accelerate from rest to 100 km/h in a time of 5.0 s.  Determine the net amount of work that must be done on the car to cause this
. What are three factors that could contribute to a source not being credible?
I = {1, 2} List all possible subsets of the given set.
Kim estimates that the faucet in her kitchen drips at a rate for 1 drop every 2 seconds. Erik wants to klnow how many times the faucet drips in a week.
Why do Andhra Pradesh donot recive any snow fall during during winter months. PLEASE HELP.....EXAM TOMORROW
all fractions between 0 and 1/4
One-half of a number is -12. Find the solution ???
among the qualities listed on the human relations scale, the most important one for the building new relationship is?
Round 13 513 to the nearest thousand
Given the inequalities y > 5x-8 and y >3x+4, find the point that satisfies neither inequalities