First we dra a triangle:
To prove that the triangles are similar we have to do the following:
Considet triangles ABC and ACD, in this case we notice that angles ACB and ADC are equal to 90°, hence they are congruent. Furthermore angles CAD and CAB are also congruent, this means that the remaining angle in both triangles will also be congruent, therefore by the AA postulate for similarity we conclude that:

Now consider triangles ABC and BCD, in this case we notice that angles ACB and BDC are congruent since they are both equal to 90°. Furthermore angles ABC and DBC are also congruent, this means that the remaining angle in both triangles will, once again, be congruent. Hence by the AA postulate we conclude that:

With this we conclude that traingles BCD and ACD are both similar to triangle ABC, and by the transitivity property of similarity we conclude that:

Now that we know that both triangles are similar we can use the following proportion:

this comes from the fact that the ratios should be the same in similar triangles.
From this equation we can find h:
![\begin{gathered} (h)/(x)=(y)/(h) \\ h^2=xy \\ h=\sqrt[]{xy} \end{gathered}](https://img.qammunity.org/2023/formulas/mathematics/college/qebw2wk2f9i8f3w1u0vbbqi13jvv1j0hrc.png)
Plugging the values we have for x and y we have that h (that is the segment CD) has length:
![\begin{gathered} h=\sqrt[]{8\cdot5} \\ =\sqrt[]{40} \\ =\sqrt[]{4\cdot10} \\ =2\sqrt[]{10} \end{gathered}](https://img.qammunity.org/2023/formulas/mathematics/college/g0l7l3boc7e0p02yuv9fmpb6a951jpu7zq.png)
Therefore, the length of segment CD is:
![CD=2\sqrt[]{10}](https://img.qammunity.org/2023/formulas/mathematics/college/olsz6ls6uckvsl03ibyrxg8aa8nqw12wdh.png)