Answer
\begin{array}{|c|c|c|}
\hline
\theta_i& t&x_f \\
\hline
40^\circ &1.78\rm\;s& 16.36\;\rm m\\
\hline
42.5^\circ &1.85\;\rm s& 16.39\;\rm m \\
\hline
45^\circ&1.923\;\rm s& 16.32\;\rm m \\
\hline
47.5^\circ&1.99\;\rm s &16.13\;\rm m \\
\hline
\end{array}
Work Step by Step
a)
As we see in the figure below, we knew the shot's initial velocity, its direction, and its initial height.
To find the horizontal distance traveled by the shot, we need to find the time it takes through the whole trip until it reaches the ground at $x_f$.
Thus,
$$y_f-y_i=v_{iy}t+\frac{1}{2}a_yt^2$$
where $a_y=-g$ since we are treating the shot as a particle model under the free-fall acceleration in which the air resistance is negligible.
$$y_f-y_i=v_{i}\sin\theta t-\frac{1}{2}gt^2$$
Plugging the known;
$$0-1.8= 12\sin 40^\circ t-\frac{9.8}{2} t^2\tag 1$$
$$ -1.8= 7.71 t-\frac{9.8}{2} t^2$$
$$ 4.9 t^2-7.71 t -1.8=0$$
Thus, $$t=\color{red}{\bf 1.78}\;{\rm s},{\;\rm OR}\;{t=}-0.206\;s$$
we shall dismiss the negative root.
Thus, the whole trip took about 1.78 s.
Now we can find the horizontal distance. We know that the horizontal velocity component is constant, so
$$x_f=\overbrace{x_i}^{0} +v_{ix}t+\overbrace{\frac{1}{2}a_xt^2 }^{0} $$
$$x_f= v_{i}\cos\theta t\tag 2$$
$$x_f =12\cos 40^\circ \cdot 1.78 $$
$$\boxed{x_f=\color{magenta}{\bf 16.36}\;\rm m}$$
b)
We used (1) when $\theta=42.5^\circ, 45^\circ, 47.5^\circ $ and solved for $t$; and then used (2) and put the answer into the table below.
\begin{array}{|c|c|c|}
\hline
\theta_i& t&x_f \\
\hline
40^\circ &1.78\rm\;s& 16.36\;\rm m\\
\hline
42.5^\circ &1.85\;\rm s& 16.39\;\rm m \\
\hline
45^\circ&1.923\;\rm s& 16.32\;\rm m \\
\hline
47.5^\circ&1.99\;\rm s &16.13\;\rm m \\
\hline
\end{array}
We can see that the maximum distance occurs at $\theta_i=42.5^\circ$