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
xenn [34]
3 years ago
14

Write a C program that creates two threads to run the Fibonacci and the Runner processes. Threads will indicate the start and th

e end of their work by printing statements in the format "Thread K Starting" "Thread K Finished", where K is the thread number. When the threads finish, the parent thread will output the results generated by the two threads by printing in the format, "The sum of first 5 numbers is: 15" and "The first 5 numbers in the Fibonacci sequence are: 0, 1, 1, 2, 3" if the user had input 5 as the value of N.
Computers and Technology
1 answer:
OleMash [197]3 years ago
3 0

Answer:

see explaination

Explanation:

#include <pthread.h>

#include <stdio.h>

int sumOfN = 0;

int arr[1000];

int n;

void * findSumOfN(void *a){

printf("Thread 1 Starting\n");

sumOfN = (n * (n+1)) / 2; //finds sum of first n natural numbers

printf("Thread 1 Finished\n");

pthread_exit(0);

}

void * fibonacci(void *a){

printf("Thread 2 Starting\n");

arr[0]=0;

arr[1]=1;

for(int i=2;i<n;i++) //find fibonacci numbers iteratively

arr[i]=arr[i-1]+arr[i-2];

printf("Thread 2 Finished\n");

pthread_exit(0);

}

int main(void){

printf("Please enter the value of n \n");

scanf("%d", &n);

if (n <= 0)

{

printf("Wrong input ! \n"); //input validation

return 0;

}

pthread_t thread1, thread2;

pthread_create(&thread1,NULL, findSumOfN, NULL); //Create threads

pthread_create(&thread2,NULL, fibonacci, NULL);

pthread_join(thread1,NULL); //Start threads

pthread_join(thread2, NULL);

printf("The sum of first %d numbers is : %d \n",n, sumOfN);

printf("The first %d fibonacci numbers are : \n",n);

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

{

printf("%d ", arr[i]);

}

printf("\n");

return(0);

}

You might be interested in
Front wheel drive vehicles typically use​
lora16 [44]

Answer:

Front wheel drive vehicles usually use positive offset wheel

Explanation:

3 0
3 years ago
Users in a corporation currently authenticate with a username and password. A security administrator wishes to implement two-fac
Katen [24]

Answer:

Option (C) is the correct answer of this question.

Explanation:

Smart card is the security administrator wishes to implement two-factor authentication to improve security.Normally this data is affiliated with either meaning, information, or both, and will be stored and transmitted within the chip of the card.A smart card, usually a Chip Card type.

  • It is a flexible card that holds an integral computer chip that preserves and sends a signal data, either database or semiconductor form.
  • Used for controlling access to a resource.
  • Data authentication, encryption, cloud storage, and software processing can be established by smart cards.

Other options are incorrect.

4 0
3 years ago
What dose it need For a device to be considered a kind of computer
const2013 [10]

Answer:

Micro controller or MCU (Microcontroller Unit)

Explanation:

Micro Controller Unit is basically a computer on a chip with all components fabricated onto it. It is the core component of a computer.

A Micro Controller has:

  • Central Processing Unit CPU
  • Random access memory RAM
  • Read-only memory ROM
  • I/O peripherals
  • Timers
  • Serial COM ports

all fabricated on a single chip so that it may be connected via buses for providing the desired functionality.

<h3>I hope it will help you!</h3>
8 0
3 years ago
Read 2 more answers
Describing Work Styles for Farmworkers and Laborers, Crop
Olegator [25]

Answer:

it is A,B,E,F,G

Explanation:

can i have brainliest please.

7 0
3 years ago
Read 2 more answers
What are the 2 levels of formatting in a word document
goldfiish [28.3K]

Answer:

Paragraph Styles and character formatting (font, color, etc.)

7 0
2 years ago
Other questions:
  • Thomas Hill claims that a fruitful way to think about the badness of destroying the environment is
    15·1 answer
  • Write a program that utilizes the concept of conditional execution, takes a string as input, and: prints the sentence "Yes - Spa
    8·1 answer
  • When you identify the data elements in a new database, you typically subdivide data elements into?
    14·1 answer
  • Technology can cause a drop in input costs.<br> a. True<br> b. False
    6·2 answers
  • Interactive television with video-on-demand capabilities changes how people watch television and how consumers access the Intern
    8·1 answer
  • Write a calculate_sq_inches_of_good_pizza function that accepts the diameter of a pizza and returns the area of the pizza minus
    7·1 answer
  • PLZZZ HELP!!!!!!!
    12·1 answer
  • if anyone is on a Chromebook, do you ever mean to press backspace, then you accidentally press the power button and think "OH CR
    11·2 answers
  • You need to know more than just facts in order to use critical thinking skills.
    5·1 answer
  • Who is the best nfl team in your mind
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!