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

Can someone help me to do this, please !!!! I didn't understand what should I have to do
HELP PLEASEEEEEEEEEE Purpose: Create a blog post responding to social commentary in The Importance of Being Eamest. Summary: In this assignment, you will create
write major 8 characteristic of folk culture​
describe in two ways how African traditional region contributes to a harmonious society ​
Which answer choice best explains a drawback of print sources? Print sources frequently provide unreliable information. Print sources contain less information t
Which situation best illustrates the political process of gerrymandering? O A. A state government creates a new district after it receives an additional seat in
If p=4 and q=6, evaluate the following expression:66/p+3q​
just help me out with this ​
Sam’s dad was in a car accident in which his neck was broken. He survived the injury but is now paralyzed from the neck down. Explain why
How can we measure the air quality and air pollution level of any particular area?​