Working through various algorithms in C