Hey guys,go serially i have given the explaination of codes in comments and if you have any doubt feel free to mail me.