To solve for the other leg, you need to use Pythagorean theory.
The theory states that C^2 = A^2 + B^2
In your case, you have to solve for B.
C = 40 (hypotenuse) A = 24 (leg 1)
The formula rewritten for B is

Now, you can solve.

Therefore, B = 32.
So the second leg is 32 feet.