Algorithm program 4