Question
This is C program assignment. Please answer as soon as possible thanks Write a program to accept an array of 20 elements and a number
This is C program assignment. Please answer as soon as possible thanks
Write a program to accept an array of 20 elements and a number to search in the main function, both array and the search-number should be global variables. Write a thread function to search and count the occurrence of the given number. Give a sleep (4) inside the loop in the thread function to model a big process working. Call 5 thread function to do search in 5 separate sections of the array. After calling all function join all threads together and in main function display the occurrence of the number in that array. If there is a race condition identify and synchronize to get the correct output.
Let the array be
1 3 4 1 5 6 2 7 1 8 9 1 2 3 1 3 1 4 6 7
And let the number to search is 1. Divide the array into 5 and call the same thread function to count the occurrence of 1 in that section.
1 3 4 1 5 6 2 7 1 8 9 1 2 3 1 3 1 4 6 7
In main the output will be 6 1s in the array.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started