He bought 4 books!
Steps:
(m = number of magazines)
(b = number of books)
m ∗ 3.95 + b ∗ 8.95 = $47.65.
If he bought 3 magazines, he would have spent $11.85 on them. However much is leftover will be the total amount of money that he spent on books.
$47.65 - $11.85 = $35.80.
He spent $35.80 on books! Now, divide how much he spent on the books by how much each one would cost.
$35.80 ÷ $8.95 = 4, which means 4 books!
Hope I helped! Let me know if I need to explain anything. :)