Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
However, this only works when the final height is the same as the launch height. What about when it's not? I could use the system of equations:
$$x=v_0\cos\theta t$$
and
$$y=v_0\sin\theta t-\frac{1}{2}gt^2$$
$\begingroup$R.W. Bird's answer is correct. Interestingly, this gives you the equation of trajectory of a projectile, which you might have studied.$\endgroup$
Solve the (x) equation for t, and put that into the (y) equation. These equations assume that the projectile starts at the origin of an (x-y) system. If you know the final (x) and (y) you can solve for the initial (θ). If you are shooting up or down a known slope, put the (x) axis along the slope and rewrite the equations to include two components of acceleration. In either case you may get two values for (θ). For maximum range these will converge. The square root in the quadratic goes to zero.