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

Which endocrine glands primarily control reproduction and fertility?
A rectangular athletic field is twice as long as it is wide. if the perimeter of the athletic field is 240240 âyards, what are itsâ dimensions?
When vinegar and baking soda are combined, bubbles begin to form. Bubbles are evidence of a chemical reaction because they - A.pop when they are touched. B.sh
what three strategies can you suggest to someone to help them lower their risk of cardiovascular disease?
What is the value of x?○15○20○60○180
i don't get it my teacher said my test is an automatic A so... Whatever i say is correct?
Hazardous wastes are placed into categories to aid in _____. A. determining toxicity B. tracking the number of yearly accidents C. determining disposal metho
For which audience is the following sentence most appropriate? The best part of the book The Call of the Wild was when John Thornton decides to keep Buck.
Load transmission from surgical vitalium subperiosteal implant to bone is by
m/n =4 identify the variation as direct, inverse, joint or combined.