I have written these codes in the most simplest way. Do refer but do not copy