Write a C program!!

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Write a C program!!

Post by answerhappygod »

Write a C program!!
Write A C Program 1
Write A C Program 1 (381.07 KiB) Viewed 33 times
(60 pts) From previous homework you are already familiar with the math function f defined on positive integers as f(x)=(3x+1)/2 if x is odd and f(x)=x/2 if x is even. Given any integer var, iteratively applying this function f allows you to produce a list of integers starting from var and ending with 1 . For example, when var is 6 , this list of integers is 6,3,5,8,4,2,1, which has a length of 7 because this list contains 7 integers (call this list the Collatz list for 6). Write a C program A6p3.c that accepts three command line arguments a,b and n which are assumed to be positive integers with a<b and n between 2 and 6 inclusive. Use pthread to create n threads to count how many integers between a and b inclusive have their Collatz list length (A) even; (B) odd. Notice that the integer 6 belongs to category (B). You should divide this list generation and length calculating task among the n threads as evenly as possible. For example, if n is 3 and there are 60 integers between a and b inclusive, then each thread is supposed to handle 60/3=20 Collatz lists. Print out the two numbers representing the counts for (A)(B) mentioned above. Use mutex or semaphore to avoid race conditions if necessary. Note: if you do not use pthread to divide the task among the threads, you will get zero points. A sample run of the compiled program is shown below. Using 3 threads. The number of integers from 11∼70 whose collatz list length is even is 31 . The number of integers from 11∼70 whose Collatz list length is odd is 29.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply