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
DIA [1.3K]
3 years ago
12

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:
Maurinko [17]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
What are the two types of programming languages?
ddd [48]

Answer:

High level language.

Low level language

Explanation:

please give brainliest

3 0
3 years ago
You can create a graphic from either an image or a string using different initializers True or false?
Bad White [126]

Answer:

It is obviously True

Explanation:

hope it helps .

3 0
3 years ago
Sara is having a tough time finding the cause of a problem on a computer she is troubleshooting. She found a possible problem bu
sp2606 [1]

<u>I will advise Sara to do research about the problem on the Internet.</u>

<u>Explanation</u>:

Internet is a network that helps in connecting one computer with other globally. Communication between the computers is possible until the computers are connected with to the Internet. Internet helps in getting information from any computer and interacts with the users of the computer.

Sara finds some issue with her computer. She was troubleshooting, but she could not find the exact problem. She was not sure with the problem that she found. It is better for Sara to do research about her problem on Internet and find the solution.

7 0
3 years ago
A thesaurus is an example of a(n)
Ivahew [28]

Answer:

D. online reference

Explanation:

An "online reference" refers to a<em> digital reference</em> that end users may utilize for their work or other daily activities. For example, if a person is looking for the <em>synonym of a particular word,</em> she may then refer to the thesaurus.

A blog is a website where you can find personal journals from different writers.

An e-book is an <em>"electronic book."</em> This allows people to read book digitally.

An e-zine is an<em> "electronic magazine." </em>This is a magazine in its digital form.

3 0
3 years ago
Read 2 more answers
An employee was watching Jessica, an IT employee, typing in many different confusing terms. Jessica explained that she needed to
zzz [600]

Answer:

Programming and Software Development

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • A friend has a CD of one of your favorite artists and has offered to let you copy it.
    8·1 answer
  • Successful attacks are commonly called ________. a. security incidents b. countermeasures c. both a and b d. neither a nor b
    10·1 answer
  • 6:57 47minutes before
    15·2 answers
  • Derek has an interest in designing video games. What requirements should he fulfill to be a game designer?
    11·1 answer
  • What are the three parts of a Function
    12·1 answer
  • Next, Sue decides to embed a chart from Microsoft Word. She copies and pastes data from a table that she has already created in
    8·1 answer
  • Hosts A and B are 20 000 km away from each other. The propagation speed of the link between them is 25000 mps. The data is place
    9·1 answer
  • Write a program to take in a time-of-day on the command-line as 3 integers representing hours, minutes, and seconds, along with
    13·1 answer
  • Line installers must complete a four-year university degree program in order to be hired.
    5·2 answers
  • Creative Commons material often costs money to use.<br><br> True<br> False
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!