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
PLEASE HELP SOMEONE!!!!!!!!! WILL GIVE BRAINLIEST!!!!!!!!!!!!!!!!!!!!!!!!! Fill in the blanks.
olasank [31]
<span> change the behavior of the program I think</span>
7 0
3 years ago
How is the numeric string that makes up a digital signature created?
Nat2105 [25]
<span>A numeric string is created by a cryptographic algorithm, which is called a hash that is used to validity of a message or authenticity of a document. The signature is verified by an algorithm that uses the stated owner of the signature's public key to accept or reject the authenticity of a signature. A certification authority's digital signature is used to verify the authenticity of digital certificates and other documents in a PKI.</span>
7 0
3 years ago
Pls answer 10 points ​
AlekseyPX

Answer:

1. C

5.b

Explanation:

1. Is c because it is in the short cut key

5. Is B because it is the last choice

3 0
2 years ago
Read 2 more answers
You want to allow members of the users group to use fdisk on the /dev/sda drive (and only that drive) and to use the yum command
masya89 [10]

Answer:

su ,sg and sudo command.

Explanation:

Whenever the user needs to enable workgroup mates should use fdisk including just that disk on both the /dev / sda disk, using the following command to update and configure the following packages. Thus he uses the command su, sg, and sudo.

So, the following commands are required according to the following statement.

6 0
3 years ago
Select the correct answer.
zmey [24]

the answer should be the letter a

3 0
3 years ago
Read 2 more answers
Other questions:
  • _____ is an information-analysis tool that involves the automated discovery of patterns and relationships in a data warehouse.
    12·1 answer
  • You are reviewing the style sheet code written by a colleague and notice several rules that are enclosed between the /* and */ c
    12·1 answer
  • what is the gpa(grade point average) you need to have or you get kicked out of robotics for middle school?
    7·2 answers
  • An application programming interface (API) is ________. A) the code the application software uses to take advantage of code writ
    11·1 answer
  • Which of the following represents the biggest difference between asymmetric and symmetric cryptography?
    9·1 answer
  • Do some Internet research on security vulnerabilities associated with SCADA and digital industrial control systems. Summarize th
    13·1 answer
  • Which of the following is true regarding data analysis? a. Disciplines and professions do not provide guidance on data analysis.
    6·2 answers
  • Which of the following activities does an effective team do?
    15·2 answers
  • How many countries don't uses the metric system?​
    12·2 answers
  • List out any four hardware and software components required for multimedia​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!