Homework 22: Functions with arrays
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Friday, March 10
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw22and submit using the204subcommand. - This is a written homework - be sure to turn in a hard-copy
of your completed assignment before the deadline. Use the
codeprintcommand to print out your code and turn that in as well.
Assignment
-
Circle one to indicate how you did for the reading assignment from
Homework 20 before class on Monday:
How carefully did you complete the reading? (Circle one)
Not at allSkimmed itRead someRead all -
Circle one to indicate how you did for the reading assignment from
Homework 21 before class on Wednesday:
How carefully did you complete the reading? (Circle one)
Not at allSkimmed itRead someRead all - Given the following definitions:
fill in the following table with the type and value of each expression. Write ERROR for both if the expression would be a compiler or run-time error.double y = 2.25; int n = 2; char s[10] = "hard"; int A[3] = {6, 9, 8}; double* X = calloc(3, sizeof(double)); X[0] = 5.1; X[1] = 5.4; X[2] = 5.7; double sqr(double z) { return z*z; } int derp(int* kptr) { if (*kptr < 5) { return 1; } else { return 99; } }expression type (or ERROR) value (or ERROR) X[0]A[1] - yA[0] - X[n]++A[2]A[1] + s[1]sqr(A[0])sqr(X[0])derp(&n)derp(A) -
Write a program called
substring.cthat reads in a target string and a test string, and reports "Yes" or "No" depending on whether the target is a substring of the test string.T is a substring of S means that T appears (in order and together!) in S somewhere. For example: "low" is a substring of "allowable" (see it? "allowable"), but not of "withhold" (see the letters are there but not in order in "withhold"), nor in "landowner" (see the letters are there and in order but not together in "landowner").
Example runs:
roche@ubuntu$./substringTarget:ispTest:mississippinoroche@ubuntu$./substringTarget:sipTest:mississippiyesroche@ubuntu$./substringTarget:issiTest:mississippiyesroche@ubuntu$./substringTarget:sssTest:mississippino -
Write a program called
pairsthat reads and integer N, and then 2 rows of N points each, and then prints out the points in (x,y) pairs, like this:roche@ubuntu$./pairsN:6x values:1 1.5 2 3.1 6 8.3y values:5.5 5.2 5.1 5.2 5.7 6.6(1,5.5) (1.5,5.2) (2,5.1) (3.1,5.2) (6,5.7) (8.3,6.6)roche@ubuntu$./pairsN:3x values:1 2 3y values:4 5 6(1,4) (2,5) (3,6)