Minecraft wiki entry for TNT_cannons, associated text: TNT cannon firing is the most random event in Minecraft, because of thousands of different sample points taken to determine dozens (or even hundreds) of different vectors which are then added together to form the base trajectory of a shot. However, it is possible to make some cannons, especially vertical mortars, 99% accurate (the charge falls back into the barrel and detonates at a specific height).
If you're really lazy and have operator privileges (or in singleplayer with cheats), you can just use commands or command blocks instead. The command /summon minecraft:tnt ~ ~2 ~ {Fuse:12,Motion:[1.0,0.0,0.0]} will fling a lit TNT eastward, starting from just above your head.
TNT cannons tend to fire further when facing east or south.