Here is the detailed program