Almost working Program 9

Program 9 is almost working but prints the results in the wrong order.