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
Laxmi was not confident that she could learn to program a computer. When she found out that two girls with similar GPA’s in her
Lapatulllka [165]

Answer:

She got motivated to work harder. She did not want to be less smarter that the other girls.

Explanation:

She was shy in the beginning, but then once she heard out the  other girls could do it very well. She then got motivated.

7 0
2 years ago
Input two numbers and print their sum products difference division and remainder​
likoan [24]

\tt n1=int(input("Enter\: first\:no:"))

\tt n2=int(input("Enter\: second\:no:"))

\tt sum=n1+n2

\tt diff=n1-n2

\tt pdt=n1*n2

\tt div=n1//n2

\tt rem=n1\%n2

\tt print("Sum=",sum)

\tt print("Difference=",diff)

\tt print("Product=",pdt)

\tt print ("Division=",div)

\tt print("Remainder=",rem)

Output:-

Enter first no:4

Enter second no:3

Sum=7

Difference=1

Product=12

Division=1

Remainder=1

7 0
2 years ago
When you gather primary or secondary data, what part of the market information management process are you participating in?
Umnica [9.8K]

Answer:

Heyyyooo!

The answer is market research.

Hope this helps!

Explanation:

Market research is the way toward gathering, analyzing and interpreting data about a market, about an item or administration to be offered available to be purchased in that advertise, and about the past, present and potential clients for the item or administration; examination into the attributes, ways of managing money, area and necessities of your business' objective market, the industry all in all, and the specific contenders you confront.  

3 0
2 years ago
Which of the following is true of how packets are sent through the Internet?
astra-53 [7]

Answer:

It is A: Packet metadata is used to route and reassemble information travelling  through the internet.

Explanation:

Step 1: The Internet works by chopping data into chunks called packets. Each packet then moves through the network in a series of hops. Each packet hops to a local Internet service provider (ISP), a company that offers access to the network -- usually for a fee

Step 2: Entering the network

Each packet hops to a local Internet service provider (ISP), a company that offers access to the network -- usually for a fee.

Step 3: Taking flight

The next hop delivers the packet to a long-haul provider, one of the airlines of cyberspace that quickly carrying data across the world.

Step 4: BGP

These providers use the Border Gateway Protocol to find a route across the many individual networks that together form the Internet.

Step 5: Finding a route

This journey often takes several more hops, which are plotted out one by one as the data packet moves across the Internet.

Step 6: Bad information

For the system to work properly, the BGP information shared among routers cannot contain lies or errors that might cause a packet to go off track – or get lost altogether.

Last step: Arrival

The final hop takes a packet to the recipient, which reassembles all of the packets into a coherent message. A separate message goes back through the network confirming successful delivery.

8 0
3 years ago
Read 2 more answers
Package Newton’s method for approximating square roots (Case Study: Approximating Square Roots) in a function named newton. This
Shtirlitz [24]

Answer:

def newton(n):

       #Define the variables.

       t = 0.000001

       esti = 1.0

       #Calculate the square root

       #using newton method.

       while True:

               esti = (esti + n / esti) / 2

               dif = abs(n - esti ** 2)

               if dif <= t:

                       break

   

       #Return the result.

       return esti

#Define the main function.

def main():

   

       #Continue until user press enters.

       while True:

               try:

         

                       #Prompt the user for input.

                       n = int(input("Enter a number (Press Enter to stop):"))

                       #display the results.

                       print("newton = %0.15f" % newton(n))

     

               except:

                       return

#Call the main function.

main()

7 0
3 years ago
Other questions:
  • Pinterest is most useful for?
    10·2 answers
  • You use Cat5e twisted pair cable on your network. Cables are routed through walls and the ceiling. A user puts a screw in the wa
    9·1 answer
  • How many bytes of information can be stored on a hard drive?
    7·1 answer
  • The editing of digital photos us about the same level of difficulty as editing an analog photo
    12·1 answer
  • What is the maximum current that should be allowed in a 5.0w 220 resistor?
    12·1 answer
  • How does the Problem-solving Process help us to solve everyday Problems?
    13·1 answer
  • . It has been said that technology will be the end of management. Maybe. How about artificial intelligence
    9·1 answer
  • A ____ is a a set of presentation rules that control how text should look. It is applied to an XML file to change the collection
    9·1 answer
  • Accenture has put together a coalition of several ecosystem partners to implement the principles of blockchain and Multi-party S
    5·1 answer
  • Question #2
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!