Equivalence of Stirling's approximations for $n!$ and $\Gamma(z)$ In this Wikipedia article for Stirling's approximation,
it is first shown that
$$ n!=\sqrt{2\pi n}\left(\frac{n}{e}\right)^n\left(1+O\left(\frac{1}{n}\right)\right)$$
for $n\in \mathbb N$,
and then it also shows that for complex $z$, the gamma funtion is approximated as
$$ \Gamma(z)=\sqrt{\frac{2\pi}{z}}\left(\frac{z}{e}\right)^z\left(1+O\left(\frac{1}{z}\right)\right)$$
and mentioned that these two asymtotic expressions are identical.
I thought if I just simply substitute $z=n+1$ in the second formula, then I get the first formula. But apparently this is not the case.
What I really don't get is why in the first formula we have $n^{n+1/2}$ and in the second formula $z^{z-1/2}$?  How these two formula can be identical?

No, what you said actually works, and I show it here.
To save the space, I omit the $O\left(\frac{1}z\right)$ terms
$$\sqrt{\frac{2\pi}{z}}\left(\frac{z}{e}\right)^z$$
Let $z=n+1$, and note $\lim_{n\to\infty}(1+1/n)^n=e$
$$\sqrt{\frac{2\pi}{z}}\left(\frac{z}{e}\right)^z
=\sqrt{\frac{2\pi}{n+1}}\left(\frac{n+1}{e}\right)^{n+1}=\sqrt{2\pi(n+1)}\frac{(n+1)^n}{e^{n+1}}\sim\sqrt{2\pi n}\frac{(n+1)^n}{e^{n+1}}$$
$$=\sqrt{2\pi n}\frac{n^n(1+\frac{1}{n})^n}{e^{n+1}}\sim \sqrt{2\pi n}\frac{n^n\cdot e}{e^{n+1}}=\sqrt{2\pi n}\frac{n^n}{e^{n}}=\sqrt{2\pi n}\left(\frac{n}{e}\right)^n$$
So you get Stirling's formula.
