HOMEWORK 3 WORKSHEET In this part of the assignment you will write pieces of code, but not entire programs. Your answers should be short (definitely not longer than 10 lines each---probably much shorter). DO NOT write complete programs! All you need to give us are the code fragments that perform the requested actions. To get the maximum benefit from these questions you should write them by hand first. If you want to check yourself, you could then implements them on the computer, but this should not be your first step. Included with each problem is a Par value. This indicates how many loops I (Isaac) used when solving each problem. Try not to use more loops than I did. This part of the assignment will not be electronically turned in, but should be submitted with your paper copy of your homework. Example: Write loop(s) to print out the numbers from 10 to 20 (inclusive). Par: 1 for loop Answer: for (i=10; i<=20; i++) printf("%d\n", i); The questions: 1) Write a loop to print out the first 10 powers of two (2, 4, 8, ..., 1024). Par: 1 for loop 2) Write code that finds the product of as many non-negative doubles as the user wishes to enter. The user will indicate that they are done by entering a negative number. Par: 1 while loop 3) The way that we'll draw a caterpillar is as some number of body segments and a head. Each body segments will be drawn as a 'o' and the head will be drawn as a 'O'. In addition, each body segment has a pair of legs, which will be drawn as '^'. For example, a caterpillar with 4 body segments would look like ooooO ^^^^ and one with 10 body segments would look like ooooooooooO ^^^^^^^^^^ Write code to prompt the user for a number of segments, and then print out the resulting caterpillar. You should loop until the user enters a non-positive number of body segements. Par: 1 while loop, 2 for loops 4) Write loops to print the following figure: ***** **** *** ** * * ** *** **** ***** You may assume you have a function int absolute(int number); which returns the absolute value of an integer. (Do NOT write this function! Just use it.) Par: 2 for loops 5) Print a graph from -5 to 5 on the X and Y axes so that there is a '*' on the graph only if X*X + Y*Y is greater than 16. Make your graph step in increments of .5 in both directions. The output of your code should look like this: ********************* ********************* ********** ********** ******* ******* ***** ***** **** **** **** **** *** *** *** *** *** *** ** ** *** *** *** *** *** *** **** **** **** **** ***** ***** ******* ******* ********** ********** ********************* ********************* Par: 2 for loops