I can't say much for the German boats, but the following link is probably more than you ever wanted to know about U.S. fleet boat deck guns. The article was written by Jim Christley:
http://www.oldsubsplace.com/Submarine%20Deck%20Guns.htm
Dave
www.pigboats.com