Algorithm program question 6