Write a C program that creates and array of 1000 random integers with values ranging from 0 to 99. It reads an integer from the command line arguments, searches for this integer in the array, and prints either “Number found!” or “Number not found…” The code to create an array of random numbers: int data[1000]; int i; for(i = 0; i < 1000; i++) data[i] = rand() % 100; You will also need to use the atoi function to get the integer value of the string read from the command line. In order to speed up the search, the program creates a child process with which it will communicate using a pipe. The two processes proceed as follows: The parent: 1. Searches for num in the first half of the array [0, 500[ 2. If it is found, it prints "Number found!" and terminates. 3. Otherwise, it reads the result of the child from the pipe, if it is a negative number, it prints "Number not found...". Otherwise, it prints "Number found!". The child: 1. Searches for num in the second half of the array [500, 1000[ 2. If it is found, it writes its location (index in the array) to the pipe and terminates. 3. If it does not find it, it writes -1 to the pipe The libraries you need to include are: stdio.h, stdlib.h, unistd.h
Write a C program that creates and array of 1000 random integers with values ranging from 0 to 99. It reads an
integer from the command line arguments, searches for this integer in the array, and prints either “Number
found!” or “Number not found…”
The code to create an array of random numbers:
int data[1000];
int i;
for(i = 0; i < 1000; i++)
data[i] = rand() % 100;
You will also need to use the atoi function to get the integer value of the string read from the command line.
In order to speed up the search, the program creates a child process with which it will communicate using a
pipe. The two processes proceed as follows:
The parent:
1. Searches for num in the first half of the array [0, 500[
2. If it is found, it prints "Number found!" and terminates.
3. Otherwise, it reads the result of the child from the pipe, if it is a negative number, it prints "Number not
found...". Otherwise, it prints "Number found!".
The child:
1. Searches for num in the second half of the array [500, 1000[
2. If it is found, it writes its location (index in the array) to the pipe and terminates.
3. If it does not find it, it writes -1 to the pipe
The libraries you need to include are: stdio.h, stdlib.h, unistd.h
Trending now
This is a popular solution!
Step by step
Solved in 2 steps