If it takes the cannonball 2 seconds to reach the maximum height, we can use the analysis of the vertical component of the velocity and the fact that the acceleration of gravity is the one acting opposite to this initial vertical component of the velocity. We know as well that at the top of the trajectory, the vertical component of the velocity is zero, and then the movement starts going down in it trajectory. So, the final velocity for the first part of the ascending movement is zero, giving us the following equation for the velocity under an accelerated movement (with acceleration of gravity "g" acting):
By knowing the vertical component of the initial velocity (19.6 m/s), and the actual magnitude of the total initial velocity (40 m/s), we can calculate what angle was the initial velocity vector forming above the horizontal. We use for such the fact that the sine of the angle relates the opposite side of a right angle triangle with the hypotenuse, and solve for the angle using the arcsin function: