1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
defon
3 years ago
8

Write a multi-threaded program that outputs prime numbers. The program should work as follows: the user will run the program and

enter a number on the command line. The program creates a thread that outputs all the prime numbers less than or equal to the number entered by the user. Also, create a separate thread that outputs this subset of the above primes that have the following property: the number that is derived by reversing the digits is also prime (e.g., 79 and 97).
Computers and Technology
1 answer:
Ierofanga [76]3 years ago
4 0

Answer:

The programming code can be found in the explanation part, please go through it.

Explanation:

Code:

#include<stdio.h>

#include<stdlib.h>

#include <pthread.h>

// function check whether a number

// is prime or not

int isPrime(int n)

{

// Corner case

if (n <= 1)

return 0;

// Check from 2 to n-1

for (int i = 2; i < n; i++)

if (n % i == 0)

return 0;

return 1;

}

void* printPrimes(void *vargp)

{

int *n = (int *)vargp;

int i=0;

for (i=2;i<=n;i++)

{

if (isPrime(i)) printf("%d\n", i);

}

}

// Driver Program

int main(int argc, char* argv[])

{

int n = atoi(argv[1]);

pthread_t tid;

pthread_create(&tid, NULL, printPrimes, (void *)n);

pthread_exit(NULL);

return 0;

}

You might be interested in
Most people entering the construction industry learn a specific craft through:
LuckyWell [14K]
Most people entering the construction industry learn a specific craft through: An apprenticeship program
7 0
3 years ago
Read 2 more answers
what font size should generally be used for the slide title to ensure that it is set off from the content
polet [3.4K]
I would say that you should use 32 pt font
4 0
3 years ago
What does this translate to?: 01001001 01110011 00100000 01100010 01110010 01100001 01101001 01101110 01101100 01111001 00100000
Anastasy [175]
"Is Brainly down?" would be the text translation
7 0
3 years ago
HELPPPPPPP!!!!!!!!!
Andrei [34K]
The compression ratio is 20:1 please mark me brainliest
3 0
2 years ago
Suppose you have two RAID arrays, one implementing RAID 3, the other RAID 5. Each has 9 disk drives in its array. If the RAID 5
Snezhnost [94]

Answer:

48 is the answer

Explanation:

16×3 is the explanation for your question

8 0
3 years ago
Other questions:
  • You save $500 in a retirement account at age 25. it increases an average of 10% per year until you are 65. which formula and res
    13·1 answer
  • How could a system be designed to allow a choice of operating systems from which to boot? What would the bootstrap program need
    14·1 answer
  • Raid level 6 is basically the same as RAID level 5, but it adds a second set of parity bits for added fault tolerance and allows
    7·1 answer
  • A _________________________ can use SOAP headers to carry meta information in its messages. A. Web service B. REST Service C. Co
    14·1 answer
  • What functions do these WLAN applications and tools perform on WLANs: airmonng, airodump-ng, aircrack-ng, and aireplay-ng
    10·1 answer
  • A subroutine may be used to refer to which of the following? Check all that apply.
    15·2 answers
  • What means the data is still saved even if you turn the computer off or unplug it?​
    5·1 answer
  • Why should information technology NOT be taught in school?​
    14·1 answer
  • An app ________ is a website that provides access to specific mobile apps that can be downloaded either for a nominal fee or fre
    14·1 answer
  • PlanthelogicforLungi’sapplicationusingpseudocode.Thelogicneedstosatisfythefollowingneeds:TheapplicationwillneedtoallowLungitoen
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!