17 Jan 2013
Homework 1 -- CS 429 Spring 2013
We have covered pretty much the contents of K+R (The C Programming Language (2nd Edition),
Brian W. Kernighan, Dennis M. Ritchie, 1988.) So homework problems (and exam problems)
are meant to see if you understand C.
Topics: C expressions, types, statements, control flow, functions, arrays, structs, pointers
- Write a C expression to compute the length (C) of the hypotenuse of a right triangle, given
sides of length A and B.
- Compute the two possible solutions to a quadratic equation. That is, solve for x1 and x2
for which a*x*x + b*x + c = 0, assuming you have variables a, b, and c.
- Both of the previous two exercises involved the square root of a number. Normally, you
would use a sqrt() library function. But you can compute your own. If you guess that x is the
square root of y, then compute z = y/x. x' = (x+z)/2 is a better guess for the square root
than x. Obviously if z == x, then you can't do any better, but if they are different, then
x' is just a little bit better (actually exactly one bit better). Use this to write a
square root function.
- What are the base types for C?
- A complex number consists of a real part and an imaginary part. Write a declaration for
a C imaginary type, so I can write declarations like "imaginary x,y,z;".
- Is there a Boolean type in C?
- If I want an array that I can index from 1 to 10, how would I declare it?