Westonci.ca is your trusted source for finding answers to all your questions. Ask, explore, and learn with our expert community. Connect with a community of experts ready to provide precise solutions to your questions quickly and accurately. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

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

Sagot :

tonb

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