Given a right triangle $\bigtriangleup BOC$ and distance $a, p, d$, what is the expected distance to needed to be traveled to reach $C$ from a point randomly selected on $AB$? (The distribution of point is uniform over $AB$)
$OB=p+a \\ AB=p \\ OC=d$
If I take the mean of $BC$ and $AC$ will the answer be correct? Also I tried,
$$\frac{\int_{a}^{a+p} \sqrt{x^2+d^2} dx}{p}$$
But, soon I realized I will be getting some area of $\bigtriangleup BAP$ not expected distance. Think about the case of $p=0$.

The integration method is correct. You'll get: $$ \frac1{2p}\left(x \sqrt{d^2+x^2}+d^2 \log \left(\sqrt{d^2+x^2}+x\right)\right)_a^{a+p} $$
Update: In this expression, we cannot let $p=0$ because throughout our calculations it is implicit that $p\neq0$. If $p=0$, the point becomes deterministic and so the distance is $\sqrt{a^2+d^2}$. We can get this by taking the limit as $p\to0$, by applying L'Hopital to the integral as the others have explained or to this expression (which is essentially the same): $$ \lim_{p\to0} \text{distance}=\frac{\frac{d}{dp}\frac12\left((a+p) \sqrt{d^2+(a+p)^2}+d^2 \log \left(\sqrt{d^2+(a+p)^2}+(a+p)\right)\right)} {\frac{d}{dp}p}\\=\frac{\sqrt{a^2+d^2}}{1}={\sqrt{a^2+d^2}}. $$