Algorithm program 2