****************************************************************************I RE
ID: 3730683 • Letter: #
Question
****************************************************************************I REALLY NEED HELP WITH THE SEARCHARRAY***************************************************************************
I just posted the entire instructions to know what we are doing. I need help with the search array the most.
For this assignment, you should use the "printArray" and "userFill" functions developed in class (which allow a user to easily fill and array from the console and print the array out) and also write 2 new functions: searchArray and sortArray.
Here are the prototypes and description of each function:
void sortArray(int array[], int size)
This takes an array and it's size and sorts the array. Nothing is returned since arrays are passed by reference automatically.
int searchArray(int array, int size, int target)
This takes an array, it's size, and a value (target) to be searched for in the array. If target is found, it's position (between 0 and size-1) is returned, if target is not found, -1 is returned.
Further Notes
You should also have a main function that allows the user to fill an array, prints the sorted array and allows the user to search for a value and returns the result.
You may choose the search and sort algorithms used, but you can't use bogoSort.
Be sure to include comments in your code, in particular you should describe the search and sort algorithms used.
Explanation / Answer
int searchArray(int array[], int size, int target) {
for(int i = 0; i < size; ++i) {
if(array[i] == target) {
return i;
}
}
return -1;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.