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
Question 9/10
Firlakuza [10]
They sometimes offer free service
5 0
3 years ago
Read 2 more answers
It is a good idea to include your teacher’s name on a title page.
kkurt [141]
I usually include my teachers name in the upper right hand corner along with the date my name and the subject.
6 0
3 years ago
Read 2 more answers
HELP ASAP DUE IN 10 MINUTES!!! HELP!!!!!<br> Problem solver<br> Logical<br> Innovative
marshall27 [118]
The first one is problem solver, the second one is Innovative, and the third one is logical.
6 0
3 years ago
Read 2 more answers
The area or the window that shows the current folder location​
Alex Ar [27]

Answer:

The focused window

Explanation:

However, please provide some more details about this because the question itself is very vague.

8 0
3 years ago
If a computer system does not have a graphics card installed in a motherboard's PCIe slot, which component handles video calcula
Klio2033 [76]

Answer:The Cpu or a chip on the Motherboard

Explanation: yore welcome

5 0
3 years ago
Other questions:
  • Choosing firm goals for your business
    7·2 answers
  • How to turn off new macbook pro when it is frozen 2017
    11·2 answers
  • What will be displayed after the following code is executed? def pass_it(x, y): z = x*y result = get_result(z) return(result) de
    13·1 answer
  • . Write a short program that asks the user to input a string, and then outputs the
    15·1 answer
  • An index purports to speed data retrieval. you, therefore, index every attribute in each table. select the likely consequence.
    15·1 answer
  • Consider the following program segment: //include statement(s) //using namespace statement int main() { //variable declaration /
    9·1 answer
  • Python
    6·1 answer
  • What is the orbit? Define
    12·1 answer
  • Ask the user to input a number less than 100. Print all the numbers from that number to 100.
    6·2 answers
  • Which of the following is not a common input device?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!