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 lines from "Mending Wall" indicate that the neighbor is willing to participate in mending the wall? We wear our fingers rough with handling them. Oh, just
Why did max weber largely disagree with karl marx's ideas on religion?
Negative and positive hallucinations describe which hypnotic experience?
y varies inversely as the square of x. If y = 12 when x = 2, then what is x when y = 3?
When you see a sign warning you there is a t-intersection ahead you must:?
you roll a number cube twice find the probability of the even. A. Rolling a 5 than a 5 B. Rolling an even than an odd
What is the area of a regular polygon with 16 sides and side length 4 inches
Question 1 Unsaved Islam, Christianity and Judaism have this in common: Question 1 options: AThey are all monotheistic BThey all follow the Bible DThey all wor
500 POINTS The p53 gene performs what function plz help will mark branliest
Sing the information on slide 24, explain how dna evidence supports the known biology of the seven cone snails.