Question: 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

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 Databases Questions!