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
Which of the following processes allows animators to use computers to input human movement that can later be transformed to crea
nadya68 [22]
Motion Capture. "it's a combination of rotoscoping with newer computer technology, allowing people to use live footage as the basis for animation without having to go through the process of drawing over it." -scienceworld .ca
7 0
2 years ago
Read 2 more answers
Select the best option that should be considered when preparing these images to.be used for the web
DerKrebs [107]
The answer is 1) JPEG  2) TIFF   3) BMP.  
<span>The best option that should be considered when preparing these images to.be used for the web :
</span>1) JPG (jpeg) - Used to compress web images to a small file size without
    sacrificing quality
2) TIFF (tiff) - Used for professional print images to save in a uncompressed 
     file format at high resolution.
3) BMP - Used for either web or print because of the ability to save high
    quality images ether compressed or uncompressed.
6 0
3 years ago
Complete the sentence.
Luda [366]
The answer is Tablets
6 0
3 years ago
output device is any peripheral to provide data and control signal to ab information processing system​
nirvana33 [79]

Answer:

Its false ita not "output" its "input"

7 0
2 years ago
Translating an algorithm into the syntax of Java is the design phase of software development.
Digiron [165]

Answer:

I think it's false

Explanation:

I don't think so. What makes me hesitate is that you may have been told that in your text or in the classroom.

Here are the steps as I understand them.

  1. Understand the problem you are trying to solve.
  2. Design a solution.
  3. Draw a flow chart.
  4. Write pseudo-code.
  5. Write code.
  6. Test and debug.

I think you've done the designing long before you start writing code or even pseudo-code.

4 0
2 years ago
Other questions:
  • Which area of the network would a college it staff most likely have to redesign as a direct result of many students bringing the
    10·1 answer
  • Dialogue is not a characteristic of functional text because...
    12·1 answer
  • A cell reference that has only one $ is referred to as a(n) ____ cell reference. alternative mixed relative absolute
    7·1 answer
  • When planning the structure of a spreadsheet, columns are for _______ items and rows are for _______ items.
    5·2 answers
  • Your supervisor has asked you to set up a RAID hard drive array in a tower system, which has a motherboard that uses the B360 ch
    10·1 answer
  • Select the correct answer from each drop-down menu.
    8·1 answer
  • Which federal agency enforces safety and health legislation and requires employers to be sure that adequate first-aid supplies a
    5·1 answer
  • Internal memory is synonymous with which memory
    8·2 answers
  • Why do chloroplasts appear only in plant cells and lysosomes appear only in animal cells?
    13·1 answer
  • Convert 12 bits to bytes​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!