This is an exercise from Hartshorne's Algebraic Geometry book. A part of this exercise is called QcQs lemma in Ravi Vakil's Foundations of Algebraic Geometry notes.