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

Write a combination of four C Language functions. The first program should inclu

ID: 3809979 • 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

Source Code:-

#include <stdio.h>
int test_prime(int);
void prime_search(int, int);
int main() {
   int n,low, high;
   printf("enter a number to check whether it is prime or not ");
   scanf("%d",&n);
   test_prime(n);
   printf("enter the interval to check whether prime numbers in this range ");
   scanf("%d%d",&low,&high);
   prime_search(low,high);
   return 0;
}

int test_prime(int n)
{
int i=0,flag=0;
for(i=2; i<=n/2; ++i)
{
if(n%i==0)
{
flag=1;
break;
}
}

if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
  
return 0;

}
void prime_search(int low,int high)
{
int i, flag;
while (low < high)
{
flag = 0;

for(i = 2; i <= low/2; ++i)
{
if(low % i == 0)
{
flag = 1;
break;
}
}

if (flag == 0)
printf("%d ", low);

++low;
}

}

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