Infosys Interview Question

asked to write a program by giving some idea