Submitted programming ex2 (q: 4)