In Coral Language: Given a sorted list of integers, output the middle integer. Assume the number of integers is always odd. Ex: If the input is 2 3 4 8 11 -1 (a negative indicates end), the output is: 4 The maximum number of inputs for any test case should not exceed 9. If exceeded, output "Too many inputs". Hint: Use an array of size 9. First read the data into an array. Then, based on the number of items, find the middle item. I found this solution online, however I dont understand it and would like it explained: integer array(9) userNums integer i integer in integer index for i = 0; i < 11; i = i + 1    if i > 9       Put "Too many inputs" to output       i = 10    else       in = Get next input          if in == -1            index = i             i = 10          else             userNums[i] = in Put userNums[index/2] to output Alos, when the program executes this code it has the correct output until the following input: 10 20 30 40 50 60 70 80 90 100 -1 Then there is an error message that says: An array index of 9 is too large; valid range of userNums: 0 - 8 the code already specififies that if i > 9 then "Too many inputs" should be put out, so therefore why is it given an error message?

Question

In Coral Language:

Given a sorted list of integers, output the middle integer. Assume the number of integers is always odd.

Ex: If the input is 2 3 4 8 11 -1 (a negative indicates end), the output is:

4

The maximum number of inputs for any test case should not exceed 9. If exceeded, output "Too many inputs".

Hint: Use an array of size 9. First read the data into an array. Then, based on the number of items, find the middle item.

I found this solution online, however I dont understand it and would like it explained:

integer array(9) userNums
integer i
integer in
integer index

for i = 0; i < 11; i = i + 1
   if i > 9
      Put "Too many inputs" to output
      i = 10
   else
      in = Get next input
         if in == -1
           index = i
            i = 10
         else
            userNums[i] = in

Put userNums[index/2] to output

Alos, when the program executes this code it has the correct output until the following input: 10 20 30 40 50 60 70 80 90 100 -1

Then there is an error message that says: An array index of 9 is too large; valid range of userNums: 0 - 8

the code already specififies that if i > 9 then "Too many inputs" should be put out, so therefore why is it given an error message? 

 

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: For each of the following pairs of expressions, give instances of relations thatshow the expressions...

A: Equivalence relation An equivalence relation on a set S is defined as a relation on S which holds ...

Q: *a Given the following declaration of the class Foo, are the following valid or invalid ways to cons...

A: a) Foo f; This is the correct way declaration as this will call the default constructor the given cl...

Q: When BL is the operand in a MUL instruction, which registers hold the product?

A: Solution: AX register holds the product when BL is the operand in MUL instruction.

Q: Briefly explain direction flag

A: Control Flags in 8086: Three control flags are used in the 8086 microprocessor to facilitate or rest...

Q: True or FalseToday, CPUs are huge devices made of electrical and mechanical components such as vacuu...

A: Central Processing Unit (CPU): CPU is a part of the computer which actually runs the program. It is...

Q: Consider a distributed system with two sites, A and B. Can site A distinguish among the following? •...

A: There's a technique that can be used for B To send an (I-am-up) message, periodically to A indicatin...

Q: Consider the following proposed rule for functional dependencies: If α → β and γ → β, then α → γ. Pr...

A: Armstrong axioms in functional dependency Armstrong axioms are used in functional dependencies and ...

Q: Give Description for MsgBox

A: MsgBox function in VBA The MsgBox function is used in Visual Basic for Applications (or VBA) that s...

Q: Write a function that determines who has won a game of tic-tac-toe. The function should receive a ch...

A: Program approach: Including header files. Declaring and defining the int checkWinner(char arr[3][3]...