Infosys interview question

asked to write a program by giving some idea