Part 1: Write the function defintion for a function named findMe that: > Takes a
ID: 3763968 • Letter: P
Question
Part 1:
Write the function defintion 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 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*The isprime function*/
int isprime (long int x)
{
long int i;
/*if x is divisible by 3 return false*/
if(x%3==0)
return FALSE;
/*initialize i with 5, start dividing x with i, increment i to 2
*after each iteration. If any one the values of i divides n, return false
*representing n is not a prime*/
for(i=5;i< =sqrt(x);i+=2)
if(x%i==0)
return FALSE;
/*return true if the for loop terminates, i.e x is prime*/
return TRUE;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*The isprime function*/
int isprime (long int x)
{
long int i;
/*if x is divisible by 3 return false*/
if(x%3==0)
return FALSE;
/*initialize i with 5, start dividing x with i, increment i to 2
*after each iteration. If any one the values of i divides n, return false
*representing n is not a prime*/
for(i=5;i< =sqrt(x);i+=2)
if(x%i==0)
return FALSE;
/*return true if the for loop terminates, i.e x is prime*/
return TRUE;