The routine is given below: