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

The belief that the U.S. should extend all the way to the Pacific Ocean because it was God's will Spoils system Harriet Tubman Manifest Destiny Dawes Act
Which poem-turned-song, written by Katharine Lee Bates, was originally called “Pikes Peak” and describes our country’s natural splendor and the patriotism of i
Mean that is computed with extra weight given to one or more variables of the sample. Weighted average Dependent variable Ordered pairs Like terms
question number 4 please help
United States lawyer and politician who advocated free silver and prosecuted John Scopes (1925) for teaching evolution in a Tennessee high school
The Scopes Trial was about: a. Freedom of the press b. Teaching evolution in school c. Prayer in school
How many representatives are there in the House of Representatives?
Two ratios (fractions) that are equal to each other.
true or false the american revolution was fought by the american colonies and china??
d = √[( x₂ - x₁) + (y₂ - y₁)] Midpoint Formula Slope Form Distance Formula Quadratic Formula