Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the following function performs a linear search of a list of 1 of length 11 for the item it, returning 0 or 1 depending on

the following function performs a linear search of a list of 1 of length 11 for the item it, returning 0 or 1 depending on whether it is not found. Many principles of good programming are violated. Describe some of these and rewrite the function in an acceptable format

int LS(int 1[], int 11, int it) /* Search 1 for it */ { int i=0 , f=0;A:if (1[i]==it) goto B; if (1[i]==it) goto B; it (i==11) goto C;/*ADD 1 TO i*/i++;goto A; B:f=1;C:return f; }

Rewrite the code so that it adheres to the principles of good programming. You can not use goto. Your program should query the user for the value to be searched for, pass that value on to the search function, and use the returned value to report the result. You can either hard wire data into the array or permit the user to fill the array interactively. Remember that an array is a static structure; it is not acceptable to set the size of an aray at run time; it must be fixed at compile time. The use of break to exit a loop function should be avoided (and will be penalizd)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

When did the situation become unable to be resolved? Why?

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago