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

mt213 Part 1: Write the function definition for a function named findMe that: Ta

ID: 3778590 • Letter: M

Question

mt213

Part 1:

Write the function definition for a function named findMe that:

Takes as input parameters: a pointer to an integer array, the length of the array, and an integer to find in the array

Returns TRUE (1), if the integer is found in the array or FALSE (0) if the integer is not found.

There should be no printf or scanf statements in this function.

Part 2:

Assume an integer array named randomArray with length 500 is populated with random data. Determine whether the value 123 is in the array with a function call to your function. Display the result with a printf statement:

Ex:

"Integer 123 was found in the array."   
or
"Integer 123 was not found in the array."

Explanation / Answer

#include <iostream>
#include <cstdlib>

using namespace std;

//function to find the number in the array
bool Findme(int *a ,int b , int c){
b=(sizeof(a)/sizeof(*a));
// loop in the array from start to end
for (int i=0 ; i<b ; i++){
// condition to check if 123 is available or not
if (a[i]==c){
cout<<"Integer 123 was found in the array"<<endl;
return true;
}
else {
cout<<"Integer 123 was not found in the array"<<endl;
return false;
}
}

}

int main(){
// array is defined
int arr[500];
// allocation random number in the array
for (int i=0 ; i < 500 ; i++){
arr[i] = rand() % 500;
//cout << arr[i]<<endl;
}
int length_of_array =(sizeof(arr)/sizeof(*arr));
Findme(arr,length_of_array,123);


}