Infosys interview question

Program to write