# Homework 2

Due: Monday 18 September.

## Semaphores

1. Read pages 19-22 of the Little Book of Semaphores and write a solution to the Barrier problem. You can use the hint on page 23 with no penalty, but please indicate on your solution whether you did.

## C Programming

1. Read Chapter 6 of the Cow Book. Pay particular attention to Question 6-1 and Answer 6-1 on page 92.

2. Write a solution to Programming Exercise 6-4.

3. Write a function that takes an amount of money expressed as a floating-point number of dollars, and returns the number of ways to make change for that amount using quarters, dimes, nickels and pennies. You don't have to generate the actual combinations, just the number of combinations.

WARNING: resist the temptation to write lots of code and then start debugging. Particularly when you are working in an unfamiliar language, it is critical to practice incremental development; that is, you should start with a small, working program and gradually add small additional features, testing as you go, until you have a program that does what you want.

For example, when I wrote my solution to this homework, I started with this:

```#include <stdio.h>
#include <math.h>

/* the declaration of round is supposed to be in math.h,
but it's not, so you need the following to avoid an annoying
warning */
double round(double);

int print_change(double amount)
{
int cents = (int) round(amount * 100.0);
printf("%d\n", cents);
}

int main()
{
print_change(0.98);
}
```