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
Identify when programmers use an Else statement.
Gnesinka [82]

Answer:

to tell the program to take a different action when the If statement answer is false

Explanation:

if x = 0:

     print('x equals 0')

else:

      print('x equals something else that isnt 0')

4 0
3 years ago
Read 2 more answers
The best how can i get. Ethiopian bank enterance examination for natural science grade 12?
zubka84 [21]

do your own work ************************************************************************************************************************************************************

5 0
4 years ago
Ano ang bunga ng pagsunod sa tamang konsiyensiya?
gladu [14]

Answer:

A.

Explanation:

mapalaganap ang kabutihan

8 0
3 years ago
Read 2 more answers
Tyesha is trying to create a resume using a template on Word, but she can not figure it out. What wrong step does she make in th
abruzzese [7]
Heading selection on Word Document
8 0
3 years ago
The DDBMS Scenario
OlgaM077 [116]

Answer and Explanation:

At C:

a.) This SQL sequence represents a remote request.

b.) This SQL sequence represents a remote request.

c.)This SQL sequence represents a distributed request. Note that the distributed request is required when a single request must access two DP sites. The PRODUCT table is composed of two fragments, PRO_A and PROD_B, which are located in sites A and B, respectively.

d.)This SQL sequence represents a distributed request.

Note that UPDATE CUSTOMER and the two INSERT statements only require remote request capabilities. However, the entire transaction must access more than one remote DP site, so we also need distributed transaction capability. The last UPDATE PRODUCT statement accesses two remote sites because the PRODUCT table is divided into two fragments located at two remote DP sites. Therefore, the transaction as a whole requires distributed request capability.

e.)This SQL sequence represents a distributed transaction. Note that, in this transaction, each individual request requires only remote request capabilities. However, the transaction as a whole accesses two remote sites. Therefore, distributed request capability is required.

At A:

f.)This SQL sequence represents a distributed request. Note that the request accesses two DP sites, one local and one remote. Therefore distributed capability is needed.

g.)This SQL sequence represents a remote request, because it accesses only one remote DP site.

h.)This SQL sequence represents a distributed request. In this case, the PRODUCT table is partitioned between two DP sites, A and B. Although the request accesses only one remote DP site, it accesses a table that is partitioned into two fragments: PROD-A and PROD-B. A single request can access a partitioned table only if the DBMS supports distributed requests.

At B:

i.)This SQL sequence represents a remote request.

j.)This SQL sequence represents a distributed request.

k.)This SQL sequence represents a distributed request. (See explanation for part h.)

5 0
3 years ago
Other questions:
  • Wharton professor Jerry Wind "believe[s] that digital networks are the key differentiator, [and] enable new forms of sharing, di
    9·1 answer
  • Which online text source would include a review of a new TV show?
    9·2 answers
  • The CPU (central processing unit), also known as a processor, is considered the brain of the computer. What is the CPU’s functio
    6·1 answer
  • How to find out if your Mac has been hacked
    12·1 answer
  • 1. in terms of technology, we often said to be living in the _____ age.???
    15·2 answers
  • When determining the amount of RAM necessary for a computer you wish to purchase, what should you consider?
    7·1 answer
  • Which statement best describes an advantage of using the Subtotal dialog box?
    14·1 answer
  • Classify the characteristics as abstract classes or interfaces.
    6·1 answer
  • What is another word for: a location in memory that contains a value?
    7·2 answers
  • What is better for a samsung tab a7 a 32 gb or 64
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!