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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started