Detailed program for program 1.