The output seems to be correct. Any explanation will help. Thanks.