consider a piece of small length $dl$ then current through this part is
$\mathrm{i}=\frac{\mathrm{I}}{\pi \mathrm{R}} \mathrm{d} \ell=\frac{\mathrm{I}}{\pi \mathrm{R}} \cdot \mathrm{R} \mathrm{d} \theta=\frac{\mathrm{I}}{\pi} \mathrm{d} \theta$
and magnetic field at $O$ due to this part of width $dl$ is $d B=\frac{\mu_{0} i}{2 \pi R}=\frac{\mu_{0}}{2 \pi R} \cdot \frac{I}{\pi} d \theta=\frac{\mu_{0} I}{2 \pi^{2} R} d \theta$
similarly take element $dl$ on opposite side
so magnetic field at $O$ due to these two elements $=2 \,d B\, \cos \theta$
$\therefore B=2 \int_{0}^{\pi / 2} d B \cos \theta=2 \int_{0}^{\pi / 2} \frac{\mu_{0} I}{2 \pi^{2} R} \cos \theta d \theta$
$=\frac{\mu_{0} I}{\pi^{2} R}(\sin \theta)_{0}^{\pi / 2} \Rightarrow B=\frac{\mu_{0} I}{\pi^{2} R}$


