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

Write a program that creates an array of 150 random integers in the range from 1

ID: 1803186 • Letter: W

Question

Write a program that creates an array of 150 random integers in the range from 1 to 200 and then, using the sequential search, searches the array 200 times using randomly generated targets in the same range (Generated 200 random data as 200 times a search purposes).
At the end of the program, display the following statistics:
a. The number of successful searches.
b. The percentage of successful searches.
c. The average number of tests per search.
To determine the average tests per search, you must count the number of loops for each search target. Each successful search will loop between 1 and 150 times; each unsuccessful search will loop exactly 150 times. The average is the sum of all the loop counts divided by the number of the searches (200).


*The problem says that i have to repeat this problem using the binary search** not super sure what that means

Explanation / Answer

Create an array of 100 random integers:

int randoms[100];

for(int i = 0; i < 100; ++i)
{
randoms[i] = rand() % range + 1;
}


Sequential search with random #'s:

int successes = 0;
int rnd_number;
for(int i = 0; i < 100; ++i)
{
rnd_number = rand() % range + 1;

for(int j = 0; j < 100; ++j)
{

if(randoms[i] == rnd_number)
{
++successes;
}
}
}
printf("Successes = %d ", successes);


I tested it a few times and got between 40 and 60 successes. ( You may get more or less )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote