Code
                               Flow chart

                             Output

                          Explanation