I don't know why this flashed through my head when I read your post, but here goes...
You know that there is talk of re-purposing a couple of Ohio subs that are no longer supposed to be used as "boomers" under the START agreements? I've seen plans to pull the missle tubes and do things like convert them for special operations. Opening sections to release small boats (mostly zodiacs and the like) as well as enhanced capabilities for dropping off divers, etc. After all, they are the quietest (and therefore stealthiest) vessels ever put to sea.
Well, what if you put in a REALLY BIG set of doors, kinda like the ones on the Space Shuttle, where the missle tubes were. Under them you put a couple of 16 inch guns like the old battle wagons used to have (or modern ones of the Bull super gun design). Interesting, if impractical idea.
You would absolutely have to fire them along the axis of the boat. Firing them perpendicular to the axis would almost certainly result in the sub rolling over. You'd never get a gunner to fire them a second time, even if you could find a skipper to give the order!
No crazier than some of the other ideas floated here so far..
The french did that before WWI. Can not remember the things name though.
British M class submarine of WWI (only a 12" gun, but the principle is the same). Worked about as well as might be expected (and nowhere nearly as well as was expected).
And the French boat: a couple of 8" guns, nothing special.