sovle problem 37.Code is ugly!