Question: 2 . ( Checking conditions and updating array index ) Write a program in C that efficiently reads user - inputted values and determines the
Checking conditions and updating array index
Write a program in C that efficiently reads userinputted values and determines the middle value if the input is within the specified limit of values.
Assume the number of integers is always odd.
A negative number indicates the end of the input the negative number is not a part of the sorted list
If the user inputs more than values, output "Too many numbers".
Ex: If the input is:
The output will be: Middle item:
Pseudocode:
Initialize NUMELEMENTS as
Declare an integer array userValues of size NUMELEMENTS
Declare variables currValue, midIndex, and i as integers
Prompt the user to enter an integer value
Read the first input value into currValue
Set i to
While currValue is greater than or equal to and i is less than do the following:
a Store currValue in userValues at index i
b Prompt the user to enter another integer value
c Read the next input value into currValue
d Increment i by
If currValue is greater than or equal to then:
a Print "Too many numbers"
Else:
a Calculate midIndex as i divided by
b Print "Middle item: followed by userValuesmidIndex
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
