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

Discuss the difference between generic and brand name drugs?
hich is the best strategy to follow when you write a report or an essay?        A. Write it in one sitting and revise it only once.   B. Work on it over several
What additional information could you add to a sketch to provide other team members with a more accurate design drawing?
Is chocolate milk healthy or unhealthy in your opinion Please explain why.
Compare the development of 2 diffrent countries. One HIC (High Income Country) and LIC (Less Income Country). Use Statistics to back up your statments. Analyse
The school band sells carnations on Valentine’s Day for $3 each. It buys the carnations from a florist for $0.50 each, plus a $18 delivery charge. When will the
Thelma was the person who wrote the sales manual originally in the beginning. use of passive voice wordiness inconsistent style
Which type of placentation is found in dogs and cats
can anybody help me please ????
Who was the most successful of the absolute monarchs.