Question: 2 . ( Checking conditions and updating array index ) Write a program in C that efficiently reads user - inputted values and determines the

2.(Checking conditions and updating array index)
Write a program in C that efficiently reads user-inputted values and determines the middle value if the input is within the specified limit of 9 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 9 values, output "Too many numbers".
Ex: If the input is: \(234811-1\)
The output will be: Middle item: 4
Pseudocode:
1. Initialize NUM_ELEMENTS as 9
2. Declare an integer array userValues of size NUM_ELEMENTS
3. Declare variables currValue, midIndex, and i as integers
4. Prompt the user to enter an integer value
5. Read the first input value into currValue
6. Set i to 0
7. While currValue is greater than or equal to 0 and i is less than 9, 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 1
8. If currValue is greater than or equal to 0, then:
a. Print "Too many numbers"
9. Else:
a. Calculate midIndex as i divided by 2
b. Print "Middle item: " followed by userValues[midIndex]
2 . ( Checking conditions and updating array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!