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

I need help with science please!
Divide 2 by 7 and turn into a fraction
Denise sold 12 of the 140 quits she made.what percent of the quilts did Denise sell? Part b :what percent did she not sell
what kind of system is the set of equations? -5x+3y=-5 -5x+3y=1
Why did most of the immigrants who came to America in the late 19th century settle in the cities? A) City living was spacious, clean, and far from overpopulate
The cost C (in dollars) for beads to make bracelets is C=4x+180, where x is the number of bracelets. Each bracelet sells for 34$ A. write an equation for the re
Neurons are highly specialized cells that have lost the ability to divide. What phase are neurons in? A) Telophase B)G0 phase C)Anaphase D)Meiosis II
During which phase do we not see the moon at all
Name the following chemical compound. be(no3)2
what was the right to be put on trial twice for the same crime