Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/** * Searches a number in a given 1 dimensional array of numbers of length size

ID: 3655504 • Letter: #

Question

/** * Searches a number in a given 1 dimensional array of numbers of length size in a linear way and stores its * index in a memory location provided. If number is not found, saves -1 in that memory location. For example: * * double numbers[] = {10.5, 20.6, 3.0, -40.2, 0}; * double num_to_search = 3.0; * int location; * linearSearch(numbers, 5, num_to_search, &location;); * * After the above statements, location has a value 2 Page 4 of 6 * which is the index of number 3.0 in the array * * Another example: * num_to_search = 100.0; * linearSearch(numbers, 5, num_to_search, &location;); * * After the above statements, location has a value -1 * as the number is not present in the array **/ void linearSearch(double numbers[], int size, double n, int* p_location);

Explanation / Answer

#include using namespace std; void linearSearch(double numbers[], int size, double n, int* p_location){ for(int i=0;i