The Ampere's law mathematical formula is,
∮→B⋅→dl=μ0I
Let the magnetic fielld along the path PQ be B and along SR be 0. As the path PS and RQ be perpendicular to the axis of solenoid, The magnetic field component along these path is zero,
Therefore the path PS and QR will not contribute to magnetic field.
Total number of turns in length l=Nl,
The line integral of magnetic field along the path PQRS is,
∮PQRS→B⋅→dl=∮QP→B⋅→dl+∮RQ→B⋅→dl+∮SR→B⋅→dl+∮PS→B⋅→dl
Thus, we have,
∮PQRS→B⋅→dl=Bl+0+0+0=Bl (1)
Now by , Ampere's circuital law,
=μ0NlI (2)
From (1) and (2),
Bl=μ0NlI
B=μ0NI