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

3s squared + 2 = -62
example of a product that has saturated its market
what is the smallest size category of soil A. Sand B. Clay C. Gravel D. Silt APEX!!
How many senators are there in the US Senate? A. 50 B. 52 C. 75 D. 100
a box of 900 paper clips costs $7.20 what is the unit price of the paper clips answer in cents
How do you solve 3/2x-4=16
Your daughter will start college one year from today, at which time the first tuition payment of \$58,000$58,000 must be made. Assume that tuition does not incr
what is the opinion of the supreme court? A. The plaintiff's side of a case B. The defendant's side of a case C. The court's final decision D. The decision of
There are 7 more girls then boys in a club there are 23 members in the club in all how many girls are there in the club? Which expression represents the number
Which function has a domain of all real numbers except x=pi/2+_npi? A. Y=cos x B. Y=cot x C. Y= 1/sinx D. Y=sec x