Corwin Perren - 931759527 Assignment 2 - ECE151 Written Questions Problem 1(10.2) a. Original code: char str[5]; scanf("%s", str); /* User types hello */ Fixed code: char str[5]; scanf("%s", &str); //user types hello Explanation: An ampersand is needed to store the value to memory, and the commenting is inconsistent with the style guide. b. Original: int a[3]; printf("%d %d %d\n", a[1], a[2], a[3]); Fixed: int a[3] = {1, 3, 5}; printf("%d %d %d\n", a[0], a[1], a[2]); Explanation: The original creates an empty array with no values in it, which makes it impossible to print its contents. The location in memory is dumped. Also, the locations printf is pulling from are one block off. The first value has location [0,0], not [1,1]. c. Original: double f[3] = {1.1, 10.01, 100.001, 1000.001}; Fixed: double f[4] = {1.1, 10.01, 100.001, 1000.001}; Explanation: The array is not large enough. d. Original: double d[2][10]; d[1,9] = 2.345; Fixed: float d[2][10]; d[1][9] = 2.345; Explanation: Used incorrect location mapping and the double was not big enough to handle this decimal. Problem 2(10.4) Original: int N; int M=90; int funct4(int n) { int i; int m = n; int a[n][n]; int b[n][m]; int c[printf("%d\n", n)][n]; int d[n][N]; int e[n][M]; int f[n] = {1, 2, 3, 4}; static int g[n]; for(i=0; i #define x 5 #define y 10 int main (int argc, char **argv) { if ((x == 5) | (x == 6)) { printf("Yup, it worked.\n"); } if ((x == 6) | (y == 10)) { printf("That worked too.\n"); } return 0; }