Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform. Get quick and reliable solutions to your questions from a community of experienced experts on our 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