Question: Collatz Sequence in C When given a positive integer, the collatz sequence is as followed. Even num = ( num/2) Odd num = (3*num +

Collatz Sequence in C

When given a positive integer, the collatz sequence is as followed.

Even num = ( num/2)

Odd num = (3*num + 1)

The conjecture states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1

Write a program that will fork n children(n is provided by the user and it should not exceed 10). Each of the children will compute the Collatz sequence for numbers in different ranges of values. The user will provide the total range of numbers to compute the Collatz sequence for.

The first 50% of the processes will computer twice as many Collatz sequences as the second 50% of processes.

. When a child finds the Collatz sequence, it should print the values to a file called results.dat.

The parent must wait for all children

When all children have completed their tasks, have the parent read all the values form the children files and output the Collatz sequence for each number to the standard output.

Should be executed by ./Collatz [Num of Processes] [Minimum Value] [Maximum Value]

Output should be

I am child number [pid num], my parent id is [pid num], I finished collatz sequence for numbers between [x] to [y]

I am child number [pid num], my parent id is [pid num], I finished collatz sequence for numbers between [x] to [y]

Processes completed....

Process PID has completed with exit code xxxx

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!