4003-231: CS1 Homework Programs #3 Due: Thur. week 8 REPETITION STATEMENTS (for, while & do loops) ===================== Change in Grading Policy ========================= Each question below has a number of points associated with it, you are required to turn in 3 points worth of problems. ===================== Things to Turn in ================================ You should turn in a printout of your program (make sure you name and the homework number is at the top. In addition, you should turn in a printout of the running of your program. To get a file that contains the output of everything that is printed on the screen (in Unix) you can use the "script" command. For information on how to use the command type man script on the Unix command line. When providing output from your program you should run your program multiple times, with a couple of the runs using data not provided in the examples. ===================== Homework Programs #2 ============================= 1. (1 point) Write a program to find the largest, smallest and average of ten positive numbers entered by the user. Note that you shouldn't have to save the numbers as you go, all you need is to check current number with the largest (or smallest) that you have seen so far. 2. (2 points) Write the function find_gcd that computes the greatest common divisor (largest number that divides two numbers). The prototype of the function should be: public static int find_gcd( int num1, int num2 ) The following algorithm can be used to compute the gcd of two numbers (num1 and num2). 1. Repeat steps (a) and (b) while num1 and num2 are not the same: a. Set D = |num1 - num2| <=== this is the absolute value b. If num1 > num2 then Set num1 = D Otherwise Set num2 = D 2. Once num1 and num2 are equal, num1 (or num2) is the gcd. 3. Write a program to draw various triangles made of stars. The user should be prompted to enter the size of the triangle. The program should make sure that the user doesn't enter an illegal size for the triangle (you can make sure that all triangles are bigger than size 2). Some triangles that you might want to try are: a) (1 point) Left Up Triangle (size 4): * ** *** **** b) (1 point) Left Down Triangle (size 5): ***** **** *** ** * b) (2 points) Right Up Triangle (size 3): * ** *** c) (2 points) Right Down Triangle (size 4): **** *** ** * d) (2 points) Isosceles Triangle (size 5): * *** ***** ******* ********* e) (3 points) Hollow Isosceles Triangle (size 4): * * * * * ******* 4. (4 points) Modify problem 3 so that the program will first asks the user which of the possible triangles to draw, then asks for the size and finally draws only the desired triangle. Your program should perform error checking to make sure the user doesn't ask for an illegal triangle.