Question: In this program the user has to insert two integer numbers: numbers which must be between 1 and 50 inclusive (i.e. 1
In this program the user has to insert two integer numbers: numbers which must be between 1 and 50 inclusive (i.e. 1<= number1 <=50) and number2 which must be between 51 and 100 inclusive (i.e. 51 <= number2 <= 100). A wrong inserted value for any number causes the output message "Invalid" to be displayed on the console and the program returns. When valid numbers are entred, they are used to in a loop that applies the following equation in each iteration: k = i* i +2* j. In this loop, "i" represnts a series of consecutive ascending even numbers starting with the value of number1 if numberl is even or starting with the value of (number1 + 1) if number1 is odd. On the other hand, ")" represnts a series of consecutive descending odd numbers starting with the value of number2 if number2 is odd or starting with the value of (number2 - 1) if number2 is even. The loop terminates when "i" becomes greater than "j". After that, the exact average, maximum, and minimum values for all the k's calculated by the loop are printed out in three seperate lines. For example, assume that the user inserted 45 and 59 as number1 and number2, respectively. The loop should start with i = 46 as the first even number and j = 59 as the first odd number. In the first iteration: k = 46*46 +2*59. In the second iteration, i = 48, j = 57, and the second k = 48*48+ 2*57. In third teration,i = 50, j = 55, and the third k = 50*50 +55*2. In fourth iteration i = 52, j = 53, and the fourth k = 52*52 + 2*53. The loop terminates after four iterations because (i = 54) > (= 51). The output will show 2518, 2810, and 2234 in three seperate lines as the average, maximum and minimum values for the four calculated K's, respectively.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
