Write a combination of four C Language functions. The first program should inclu
ID: 3810455 • Letter: W
Question
Write a combination of four C Language functions.
The first program should include a test_prime() function that returns a 0 if the integer argument is not a prime number, and a 1 if it is a prime number using function — int test_prime(int n);
The second program should also use a prime_search() function used to start a routine for the prime search threads. It should have a range of integers and determine which integers in that range are prime. Each prime number should be printed on a separated line to a file named “primesx”, where x is the thread number using function — void *prime_search(void *param);
The third program should include a mini_shell() function that serves as a start routine for the interactivity thread. This function will display a prompt and take commands from the user using function — void *mini_shell(void *param)
The following single character commands must be supported:
‘1’ : will return the integer prime search thread 1 is currently checking
‘2’ : will return the integer prime search thread 2 is currently checking
‘a’ : will return the integers both prime search thread 1 and 2 are currently checking
The fourth program includes a main() that searches the first five million integers for prime numbers by using two threads. A third thread is created to enable the user to check the search status of the two prime search threads while they are running. When the prime number search is completed the main function will combine the three functions.
Explanation / Answer
#include<stdio.h>
#include<math.h>
int test_prime(int n)
{
int count = 0; i;
if(n <= 1)
return 0;
for(i=2; i<=sqrt(n); i++)
{
if(n%i == 0)
++count;
}
if(count == 0)
return 1;
else
return 0;
}
int main()
{
int n, val;
scanf("%d", &n);
val= test_prime(n);
if(val == 0)
printf("%d is not a prime number ", n);
else
printf("%d is a prime number ", n);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.