The martian is the better book. It's one of the best examples of "science applied to problems" I've read. Unfortunately the movie did it a dirty, and cut out a lot of the good parts.
Project hail Mary is an excellent book, but not quite to the level of The Martian (REALLY enjoyed it however!). The film is a better adaptation. It still cuts a lot of science out, but at least plays lip service to it having happened. It also captures the characters PERFECTLY.