Homework 2 ENEE 114 Spring 2007 POSTED: 12:20 pm Saturday March 10 DUE: 11:59 pm Monday March 26 * name your answers as hw2.1.c, hw2.2.c, ..., and submit each of them via the GLUE submit command * make sure that you document each hw2.x.c file /****************************************************************************/ 1. Write a C program to read in a list of integers from the screen and print them out while expanding all the shorthand notations like 8-12 into its complete list 8, 9, 10, 11, 12. The followings are some sample input-output pairs input: 1-4 output: 1 2 3 4 input: 1 4-6 7-9 output: 1 4 5 6 7 8 9 input: 1-3 5 8 output: 1 2 3 5 8 2. Write a C program that converts a positive decimal integer into octal. The following shows by example how to do so. Given 327 in decimal, 1) divide 327 by 8, we get 40 as quotient and 7 as remainder 2) divide 40 by 8, we get 5 as quotient and 0 as remainder 3) divide 5 by 8, we get 0 as quotient and 5 as remainder 4) the octal representation of 327 is 507 3. Write a program that asks user for an integer a and a positive integer b, and outputs the value of a to the power of b. Use a loop to calculate the power. You cannot use the power function in the math.h library. For example, z: a.out Enter an integer a and a positive integer b:3 1 Power(3, 1) = 3 z: a.out Enter an integer a and a positive integer b:-2 9 Power(-2, 9) = -512 z: a.out Enter an integer a and a positive integer b:9 -2 b = -2 is not positive. z: 4. Write a C program that takes two inputs, a and b, and outputs c defined as follows: c = 0, if a = 0 and b = 0 c = 1, if a = 0 and b = 1 c = 1, if a = 1 and b = 0 c = 0, if a = 1 and b = 1 Error, otherwise (Hint: If you use switch statement, think about 2*a+b.) 5. Debug the following program and submit the correct program under name hw2.5.c. Make sure that your corrected program complies and test it. /* this program reads in nine numbers and prints out the largest number #INCLUDE int main(void) { int k=0, big=0; int 9numbers[9]; print("Please enter nine integers:"); while (k <= 9) { scanf("%d", 9numbers[k]); ++k; } while (k <= 9) // find the largest number { if (big > 9numbers[k]) big = 9numbers[i]; k++; } printf("%d\n", Big); return 0; }