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
A threat analyst is asked about malicious code indicators. Which indicator allows the threat actor's backdoor to restart if the
joja [24]

Indicators of compromise enable system administrators and information security professionals to detect intrusion attempts or malicious activities.

Your information is incomplete as the options aren't provided. Therefore, an overview of indicators of compromise will be given.

Indicators of compromise means the pieces of forensic data that are found in files or system log entries to identify malicious activity on a network or system.

Indicators of compromise help IT and information security professionals to detect malware infections, data breaches, etc. Examples of indicators of <em>compromise</em> include log-in red flags, unusual outbound network traffic.

Read related link on:

brainly.com/question/25522987

8 0
3 years ago
Indicates the beginning and ending of your code written in HTML
lawyer [7]

Answer:

<body> ...</body>

indicates the beginning and ending of your code written in HTML

Explanation:

4 0
3 years ago
Someone knows a good compiler for iPad? It has to be an app
aksik [14]
Jedona is a good one
5 0
3 years ago
It is a part of webpage that contains the logo ang branding of the web page​
Novay_Z [31]
The answer is Header/Banner
6 0
3 years ago
Edra wants to consolidate the data from each of the regions. Switch to the Consolidated Sales worksheet, then update the workshe
VashaNatasha [74]

Answer:

a. In cell A6, enter a formula without using a function that references cell A6 in the Washington worksheet.

b. Copy the formula from cell A6 to the range A7:A9 without copying the formatting.

Explanation:

Microsoft Excel is a spreadsheet application used for data analysis and statistical calculation. The worksheet is made of columns and rows like a table and labeled alphabetically and numerically respectively. Several worksheets can be referenced in an excel workbook

To consolidate data in excel, reference a cell from another worksheet in the formula of the current worksheet and copy the formula from the cell to a given range of cells, without copying the formatting of the cell.

7 0
3 years ago
Other questions:
  • Write a program named TypingGrades that allows a user to enter a student’s number of words typed. The output is the letter grade
    9·1 answer
  • Num = int(input("Enter a number: "))
    5·2 answers
  • A(n) _______ allows an attacker to use a network structure to send large volumes of packets to a victim.
    5·1 answer
  • You are installing an updated driver for a hardware device on your system. A dialog box displays indicating that Microsoft has d
    15·1 answer
  • Select the correct answer from each drop-down menu. What skills should Tara hone to get a job in testing? Tara is a recent compu
    12·1 answer
  • Assume that a file containing a series of integers is named numbers.dat and exists on the computer's disk. design a programt hat
    15·2 answers
  • UserInp = input("Did you like the story?")
    7·1 answer
  • Memory cards from your cameras (SD cards) and flash drives are examples of __________.
    13·1 answer
  • A related database stores data in the form of______
    15·1 answer
  • What do you mean by computer ethics?​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!