Create a program that uses a while loop to sum only the even numbers from 1 up to and including 60. Display the total sum of these even numbers. Make sure you have appropriate comments and output to explain the program's function. After completion and testing, zip the folder and submit via the Assignments link in BlackBoard. You should browse and attach the folder via the local file button and then select the submit button.

Respuesta :

Answer:

C++ program with step by step code explanation and output result is provided below.

Code & Explanation:

We are required to create a program to sum even numbers from 1 to 60 inclusive using a while loop.

#include <iostream>

using namespace std;

int main()

{

int sum=0;   // variable to store the sum of even numbers

int index=1;   // variable to count the number of times while loop runs

while(index <= 60)   // while loop iterates until index is less or equal to 60

{  

 if(index%2==0)     // to find out whether the number is even or not

     sum=sum+index;   // if the number is even add it to total sum

     index=index+1;   // increase the index by 1 to continue the while loop

}      

cout<<"The sum of even numbers from 1 to 60 is: "<<sum<<endl;  

// to print the total sum of even numbers from 1 to 60 inclusive  

return 0;

}

Output:

The sum of even numbers from 1 to 60 is: 930

Ver imagen nafeesahmed