Question: WRITE PROGRAM IN C THAT MEETS THE FOLLOWING REQUIREMENTS: Declare a number ( n ) as a global variable in main function. Create 2 threads

WRITE PROGRAM IN C THAT MEETS THE FOLLOWING REQUIREMENTS:

  • Declare a number (n) as a global variable in main function.
  • Create 2 threads in the program.
    • Create the first thread to generate and print the Collatz-sequence from n.
    • Another thread to find the factorial of the number n.

HERE IS A BASE EXAMPLE OF THE PROGRAM. SOME THINGS NEED TO BE CHANGED:

#include #include

static int counter=1;

void *mythread(int n){ printf("%d ",n); int i; for(i=1;i

int main(int argc,char *argv[]){

pthread_t t1,t2; printf("Main starts here "); pthread_create(&t1,NULL,mythread,3); //sleep(2); pthread_create(&t2,NULL,mythread,4);

pthread_join(t1,NULL);

pthread_join(t2,NULL);

printf("End of Main %d ",counter); return(0); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!