Using the principle of conservation of momentum, the velocity of the bullet just before the collision is related to the velocity of the combined block and bullet system after collision. The block with mass \( M \) and bullet with mass \( m \) move together after collision.
The potential energy of the block after the collision is given by:
\[
P.E. = (M + m)gh
\]
The kinetic energy of the bullet before the collision is related to the velocity as:
\[
K.E. = \frac{1}{2}(m + M)v^2
\]
By equating the kinetic and potential energies, we get:
\[
\frac{1}{2}(m + M)v^2 = (M + m)gh
\]
Thus:
\[
v = \sqrt{2gh \left(1 + \sqrt{\frac{m}{M}}\right)}
\]
So the correct answer is (C).