They technically "sank" more ships by gunfire than by torps as they often used a torp to hit a ship which, if it didn't sink immediately, was then left behind by the convoy as it slowed to a stop and it was then finished off by the surfaced U-Boat hours later using the deck gun.
Additionally, as torps were very limited but deck gun shells were plentiful, a lone ship wouldn't be torped but hit with the deck gun instead, leading to the invention of allied Q-Ships, which looked like a normal unarmed ship but was actually heavily gunned and designed to engage the surfaced U-Boat thinking it was about to get a easy kill.