Cognizant interview question

write a code for the given program