sum modified to give sum and show array