Write a program in C that accepts a positive integer number X from the user and then uses 5 synchronized threads in order to do the following :
F2020-CS4350-HW-7-C-MultiThread-Programs CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 1 Programming Assignment 7 Optional - It Will Replace One of Your Lowest Programming Assignment Grades Due Date : Monday November 30th , 2020 No later that 5:15 pm NAME : __________________________ Course Number / Name : ___________________ Assignment Number : ___________ Due Date : ______________________ Write a program in C that accepts a positive integer number X from the user and then uses 5 synchronized threads in order to do the following : 1. The first thread prints all odd numbers between 1 and X inclusive. 2. The second thread prints all the even numbers between 1 and X inclusive. 3. The third thread prints the sum between 1 and X inclusive 4. The fourth thread print the hailstone sequence for the number X . 5. The last thread determines whether or not X is an Armstrong number. CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 2 Note : • Thread 1 , 2 , 3 must be synchronized. Threads 4 and 5 are also synchronized. Must use lock and unlock when implementating this program. Look at the sample run. • Positive integer must be grater than 0. • Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You write a sequence of numbers, one after another. Start by writing n. If n is even, then the next number is n/2. If n is odd, then the next number is 3n + 1. Continue in this way until you write the number 1. • A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself. For example: 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number. 12 is not equal to 1*1*1+2*2*2 // 12 is not an Armstrong number CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 3 Sample Run Welcome to Husain Gholoom’s Thread App This program will do the following : Accepts an integer number X from the user and then uses 5 synchronized threads in order to do the following : 1. The first thread prints all odd numbers between 1 and X. 2. The second thread prints all the even numbers between 1 and X. 3. The third thread prints the sum between 1 and X. 4. The fourth thread print the hailstone sequence for the number X . 5. The last thread determines whether or not X is an Armstrong number. Enter an Integer > 0 --- > 7 CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 4 All odd / Even / Sum of numbers between 1 and 7 Function1-Odd : 1 Function2-Even : 2 Function3-Sum : 3 Function1-Odd : 3 Function2-Even : 4 Function3-Sum : 10 Function1-Odd : 5 Function2-Even : 6 Function3-Sum : 21 Function1-Odd : 7 All odd / Even / Sum Threads Exits Function4 - Hailstone Process Started Input Number 7 Hailstone sequence of 7 is : 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 Function5 - Armstrong Process Started 7 is not an Armstrong number Hailstone Thread Exits Armstrong Thread Exits End of Main program ---- > Sum = 28 Program by Husain Gholoom 11 – 30 - 2020 CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 5 Welcome to Husain Gholoom’s Thread App This program will do the following : Accepts an integer number X from the user and then uses 5 synchronized threads in order to do the following : 1. The first thread prints all odd numbers between 1 and X. 2. The second thread prints all the even numbers between 1 and X. 3. The third thread prints the sum between 1 and X. 4. The fourth thread print the hailstone sequence for the number X . 5. The last thread determines whether or not X is an Armstrong number. Enter an Integer > 0 --- > -7 **** Number must be grantor than 0 *** Program by Husain Gholoom 11 – 30 - 2020 CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 6 Welcome to Husain Gholoom’s Thread App This program will do the following : Accepts an integer number X from the user and then uses 5 synchronized threads in order to do the following : 1. The first thread prints all odd numbers between 1 and X. 2. The second thread prints all the even numbers between 1 and X. 3. The third thread prints the sum between 1 and X. 4. The fourth thread print the hailstone sequence for the number X . 5. The last thread determines whether or not X is an Armstrong number. Enter an Integer > 0 --- > a **** Number must be grantor than 0 *** Program by Husain Gholoom 11 – 30 - 2020 CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 7 Rules : 1. The programs must be syntactically and logically correct. The program will be tested using the Zeus ( Unix OS ) at the university. 2. The programs must be documented and your names , course and section number , your group number, assignment number , due date , and instructor’s name should be included as part of your program documentation. A brief description of the program must also be included 3. Must properly format the output as shown above . 4. You must upload your solution using Canvas – Make sure you include the above as comments in your program. Make sure that you name your homework document as follows : F20_FirstName_LastName_PA7.c For example F20_Husain_Gholoom_PA7.c No late assignment will be accepted and no extensions will be given The following compiling command will be used when compiling the Program gcc -lpthread F20_Husain_Gholoom_PA7.c Not allowed to customize the command CS4350 -‐ Unix Programming Fall 2020 – Husain Gholoom – Senior Lecturer in Computer Science Page 8 5. Must place the following information on top left of the first page of your assignment as comments before the start of the program. Add the missing information NAME : ______________________ Course Number / Name : _______________________ Assignment Number: ___________ Due Date: ________________ The following points will be deducted if : • Compilation Errors, missing electronic copy , not written in c programming language, submitting .zip file, submitting files other than .c … etc. ( - 10 points ) • The program will be complied as follows : gcc -lpthread