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
Whitch action should a user take to ensure that formatting is applied to a row? A. use the ctrl+a keys. B. highlight the whole t
Alina [70]

Answer: Drag the cursor across the entire row.

8 0
4 years ago
In the formula =C5*$B$3, C5 is what type of cell reference?
Feliz [49]

Answer:

relative

Explanation:

i just got a 100 and it says its right on odsyware

8 0
3 years ago
Which describes the relationship between enterprise platforms and the cloud?
AlladinOne [14]

Answer:

All enterprise platforms are cloud based.

4 0
3 years ago
1. Do you agree that Facebook is the best social media platform to use for interpersonal communication? Why or why not?
anzhelika [568]
Nah I don't there is a BUNCH of creeps on Facebook so no!
4 0
4 years ago
Read 2 more answers
Visually impaired people cannot use a mouse to navigate web pages. How can web page designers ensure that such individuals are a
SSSSS [86.1K]

Answer:

Keyboard

Explanation:

Visually impaired users usually rely on the keyboard for navigating a website, the concept of taking notice of disabled people while building your website or applications is called accessibility or a11y for short, where the user uses the tab key to focus on various form elements and enter for selection, etc. it is believed that websites with proper accessibility reaches and cater for more users.

8 0
3 years ago
Read 2 more answers
Other questions:
  • ____ technologies support digital transmission for both voice and data
    12·1 answer
  • data structureWe have two containers: one has a capacity of three gallons of water, the other five gallons. Both are initially e
    11·1 answer
  • True and False: High-speed Internet service is free form of information technology that these businesses can utilize.
    13·1 answer
  • Write a program that prompts the user to input a number. The program should then output the number and a message saying whether
    10·1 answer
  • An organization’s SOC analyst, through examination of the company’s SIEM, discovers what she believes is Chinese-state sponsored
    12·1 answer
  • Complete the function doubling_time that takes two parameters bal and apr and uses a while loop compute the number of years it t
    10·1 answer
  • 2. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The object
    14·1 answer
  • problemas demográficos o movilizaciones que se generaron a lo largo de la historia de Honduras debido a la explotación minera​
    7·1 answer
  • What do you think is the most important part of the history of internet what event has had the biggest impact on your daily life
    7·2 answers
  • Which of the following is an operating system?<br> MacBook Air<br> Windows 10<br> Dell
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!