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

Alison wants to find out how much time people spend reading books. She is going to use a questionnaire. Design a suitable question for Alison to use in her ques
Which physical feature has most limited the movement of people living in North America ?
The tropical climate zone is in which two states?
Which sentence correctly forms the plural of the letter c?   A.How many c's are in accordion?   B.How many cs'
How many union ships did the Virginia sink?
in what situation does friction make an object change its shape
Which sentence correctly forms the plural of the letter R? A. Three R's make up her initials.
What type of reaction occurs when you strike a match?
The tickets for the concert are selling for $12.00. Juanita is going to the concert with a group of 25 people. There is a discount of 1/8 off each ticket for gr
Find the sum of 2/9+1/9?