Integral formulas involving continued fractions Ramanujan posed the following formulas as questions in the Journal of Indian Mathematical Society:
$$\int_{0}^{\infty}\dfrac{\sin nx\,\,dx}{{\displaystyle x + \dfrac{1}{x +}\dfrac{2}{x +}\dfrac{3}{x +}\dfrac{4}{x + \cdots}}} = \dfrac{\sqrt{\dfrac{\pi}{2}}}{n + \dfrac{1}{n +}\dfrac{2}{n +}\dfrac{3}{n +}\dfrac{4}{n + \cdots}}\tag{1}$$
$$\int_{0}^{\infty}\dfrac{\sin\left(\dfrac{\pi nx}{2}\right)\,\,dx}{{\displaystyle x + \dfrac{1^{2}}{x +}\dfrac{2^{2}}{x +}\dfrac{3^{2}}{x +}\dfrac{4^{2}}{x + \cdots}}} = \dfrac{1}{n +}\dfrac{1^{2}}{n +}\dfrac{2^{2}}{n +}\dfrac{3^{2}}{n + \cdots}\tag{2}$$
From this post we know that $$\phi(x) = e^{x^{2}/2}\int_{x}^{\infty}e^{-t^{2}/2}\,dt = \frac{1}{x +}\frac{1}{x +}\frac{2}{x +}\frac{3}{x + \cdots}\tag{3}$$ and hence the first integral formula reduces to $$B = \int_{0}^{\infty}\phi(x)\sin nx\,\,dx = \sqrt{\frac{\pi}{2}}\phi(n) = \phi(n)\int_{0}^{\infty}e^{-t^{2}/2}\,dt\tag{4}$$ Considering the integral $$A = \int_{0}^{\infty}\phi(x)\cos nx\,\,dx$$ we can see that
\begin{align}
A + iB &= \int_{0}^{\infty}e^{x^{2}/2 + inx}\int_{x}^{\infty}e^{-t^{2}/2}\,dt\,dx\notag\\
&= e^{n^{2}/2}\int_{0}^{\infty}e^{(x + in)^{2}/2}\int_{x}^{\infty}e^{-t^{2}/2}\,dt\,dx\notag
\end{align}
I am not so much used to theory of complex integration, but I think it should be possible to interchange the limits of integration above and get the values of $A$ and $B$ without going too much into the theory of complex integration. But still it does not seem rigorous to me. Please let me know if I am on the right track (or may be this approach can be made rigorous) or suggest alternative approach.
For integral $(2)$ I have no idea of the continued fraction used there. Any clues to the solution of $(2)$ would also be greatly helpful.
 A: Another "late" answer, following the idea of interchanging integrations. Denote
\begin{align*}
\mathcal{S}\{f\}(s)&=\int_0^\infty f(t)\sin st\,dt,&\mathcal{L}\{f\}(s)&=\int_0^\infty f(t)e^{-st}\,dt,\\\mathcal{C}\{f\}(s)&=\int_0^\infty f(t)\cos st\,dt,&\mathcal{K}\{f\}(s)&=\int_0^\infty f(t)\frac{s}{s^2+t^2}\,dt;
\end{align*}
then, for "good enough" $f$, we should have $$\mathcal{S}\big\{\mathcal{L}\{f\}\big\}=\mathcal{K}\{f\},\qquad\mathcal{K}\big\{\mathcal{C}\{f\}\big\}=\frac\pi2\mathcal{L}\{f\}.$$
For our needs, it's sufficient to see that the first of these equalities holds for bounded $f\in C^1$ (indeed, it holds for constant $f$, thus we may assume $f(0)=0$; then, for $g=\mathcal{L}\{f\}$, we have $g(s)=O(s^{-2})$ as $s\to\infty$, and $g(s)=O(s^{-1})$ uniformly; so, the integral for $\mathcal{S}\{g\}$ converges absolutely, and the interchange is allowed) and, similarly, the second one holds for $f\in L^1$.
Now $\phi(s)=e^{s^2/2}\int_s^\infty e^{-x^2/2}\,dx=\int_0^\infty e^{-st-t^2/2}\,dt$ after $x=s+t$, that is $\phi=\mathcal{L}\{f_1\}$ for $f_1(t)=e^{-t^2/2}$, and $\mathcal{C}\{f_1\}=(\pi/2)^{1/2}f_1$ (there are many ways to show this known equality; a possible approach uses contour integration of $e^{-z^2/2}$ along the boundary of $[-R,R]+i[0,s]$, with $R\to\infty$), which gives $(1)$: $$\mathcal{S}\{\phi\}=\mathcal{S}\big\{\mathcal{L}\{f_1\}\big\}=\mathcal{K}\{f_1\}=(2/\pi)^{1/2}\mathcal{K}\big\{\mathcal{C}\{f_1\}\big\}=(\pi/2)^{1/2}\mathcal{L}\{f_1\}=(\pi/2)^{1/2}\phi.$$
Similarly, the integral in $(2)$ is $\mathcal{S}\big\{\mathcal{L}\{f_2\}\big\}(\pi n/2)$ with $f_2(t)=1/\cosh t$, as we know from the linked question. This time, we use $\mathcal{C}\{f_2\}(s)=(\pi/2)f_2(\pi s/2)$; again, a possible way to show the latter is to use contour integration of $e^{isz}/\cosh z$ along the boundary of $[-R,R]+i[0,\pi]$.
