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]
4 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]4 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
Which RAID configuration, known as byte-striped with error check, spreads the data across multiple disks at the byte level with
wel

Considering the computer system technology, the RAID configuration, known as byte-striped with an error check, and spreads the data across multiple disks at the byte level with one disk dedicated to parity bits is known as <u>RAID Level 5.</u>

<h3>What is the RAID Level 5?</h3>

RAID Level 5 is the Redundant Array of Inexpensive (or Independent) Disks Level 5. RAID Level 5 works on strips to transfer data over multiple disks in an array.

RAID Level 5 is also known to record information, with the ability to withstand numerous failures.

<h3>Other types of Redundant Array of Inexpensive (or Independent) Disks</h3><h3 />
  • RAID level 0
  • RAID level 1
  • RAID level 2
  • RAID level 3
  • RAID level 4

Hence, in this case, it is concluded that the correct answer is RAID Level 5.

Learn more about RAID configuration here: brainly.com/question/9305378

8 0
3 years ago
Which of the following is NOT included in the entry career pathway?
SVETLANKA909090 [29]
Looking for jobs is NOT included in the entry career pathway. When you state entry career path, you need to reconsider what kind of job you are going to proceed in. 

Happy studying ^-^
3 0
3 years ago
Read 2 more answers
Explain how analog computers are used to process data generated by ongoing physical process​
ioda
Hi hi :)

Analog computers store data in a continuous form of physical quantities and perform calculations with the help of measures.

Okay bye :)
7 0
2 years ago
What does the chart elements option allow you to change
S_A_V [24]
You can change the format of individual chart elements, such as the chart area, plot area, data series, axes, titles, data labels, or legend.


5 0
3 years ago
Read 2 more answers
Consider three strings instr1, instr2 and instr3 having only lowercase alphabets. Identity a string outstr, with the smallest po
soldi70 [24.7K]
10 points is nothing to answer this junk just saying
7 0
3 years ago
Other questions:
  • You can drag a cell to a new location by pointing to the cell border until the pointer displays a _______ arrow, and then draggi
    9·2 answers
  • What form of internet access currently uses a technology called 4gb?
    10·1 answer
  • HURRY!!!!!!
    5·1 answer
  • In python:
    14·1 answer
  • Indicate the time efficiency classes of the three main operations (i.e., FindMax, DeleteMax, and Insert) of the priority queue i
    11·1 answer
  • Write the name of the tab, command group, and icon that is used to create multilevel lists.
    12·1 answer
  • You are an online training company and stream a lot of training videos from your
    12·1 answer
  • Which design monument beginning with A inspired the chrysler building in New York​
    14·1 answer
  • Time management is the ability to use time effectively.
    13·2 answers
  • How are the four characteristics of the db approach related to the four functions of a dbms?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!