Question: Ask the user to enter an integer between 1 and 2 0 . Use a while loop to calculate the sum of the first N
Ask the user to enter an integer between and
Use a while loop to calculate the sum of the first even numbers.
Display the calculated sum.
Inside the while loop, you must also count how many times the loop is executed. Display this count after printing the sum.
Note: Make sure to handle the user input gracefully. If the user enters an invalid number, prompt them to enter again.
Please enter an integer between and :
is an invalid input! Please enter an integer between and :
is an invalid input! Please enter an integer between and :
The sum of the first even numbers is:
The loop executed times.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
