Solution to program 5