77.8k views
1 vote
2- Write aC+ program that calculates the sum of all even numbers from [1000,2000], using the while loop.

User Gene C
by
3.8k points

1 Answer

3 votes

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;

}

Step-by-step explanation:

This will output:

sum of even numbers in [1000..2000] = 751500

User Tal Bereznitskey
by
3.7k points