From the balanced equation, we see that 1 mol of Mg(NO3)2 is produced for 2 moles of HNO3. Since this is a "mass/mass" problem, you need the molar masses of each of these two compounds. Using the formulas & the atomic masses, we get 148 g/mol for the magnesium nitrate & 63 g/mol for the nitric acid. So,
(148 g Mg(NO3)2 / 1 mol Mg(NO3)2) (1 mol Mg(NO3)2 / 2 mol HNO3) (1 mol HNO3 / 63 g HNO3) (4 g HNO3)
= 46.98 = 47 g Mg(NO3)2
Following the same logic you can di the 2nd question.