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

Part 1: Write the function defintion for a function named findMe that: 1) Takes

ID: 3763994 • Letter: P

Question

Part 1: Write the function defintion for a function named findMe that:

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

2) 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 the 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.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int findMe(int* a,int l, int f)
{
   int i;
   for(i=0;i<500;i++)
   {
       if(a[i]==f)
       {
           return 1;
       }
   }
   return 0;
}

void main()
{
   int randomArray[500],i;

   for(i=0;i<500;i++)
   {
       randomArray[i]=rand()%100;
   }

   int a=findMe(randomArray, 500, 123);
   if(a==1)
   {
       cout<<"Number found";
   }
   else
   {
       cout<<"Number not found";
   }
   getch();
}