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 period was the “golden age of dinosaurs”? a. the Triassic Period b. the Jurassic Period c. the Cretaceous Period d. the Tyrannosaurus Period
What is 1997 from 2014????????????
how do day and nightat uranus's equator change asthe uranus revolves around the sun?
Which period was the “golden age of dinosaurs”? a. the Triassic Period b. the Jurassic Period c. the Cretaceous Period d. the Tyrannosaurus Period
which explorer sailed for france?
A tree was chopped down and cut up in a local forest.The tree changed in shape.What kind of change took place?A.chemical changeB.physical change C.phase changeD
how do day and nightat uranus's equator change asthe uranus revolves around the sun?
what does etymology study?
Can someone please help me ?
Why does Louis XIV want to expand France's border?