After stuggling in deriving this, I found similar one on wikpedia. References below. May be I will add Mathematica implementation for this later....
The goal is to find recusive formula for \(\int \cos (x)^n \,dx\). Starting by rewriting it as \begin {equation} \int \cos (x)^n \,dx = \int \cos (x)^{n-1} \cos (x) \,dx \end {equation} Integrating by parts \(\int u\,dv = (uv)-\int v\, du\) and letting \(u=\cos (x)^{n-1}, dv=\cos (x)\), hence \(du=-(n-1)\cos (x)^{n-2} \sin (x)\) and \(v=\sin (x)\) the above becomes \begin {align*} \int \cos (x)^n \,dx &= \cos (x)^{n-1} \sin (x) + \int \sin (x) (n-1)\cos (x)^{n-2} \sin (x) \,dx \\ &= \cos (x)^{n-1} \sin (x) + \int (n-1)\cos (x)^{n-2} \sin ^2(x) \,dx \\ &= \cos (x)^{n-1} \sin (x) + \int (n-1)\cos (x)^{n-2} (1-\cos (x)^2) \,dx \\ &= \cos (x)^{n-1} \sin (x) + (n-1) \int \cos (x)^{n-2} - \cos (x)^n \,dx \\ &= \cos (x)^{n-1} \sin (x) + (n-1) \int \cos (x)^{n-2}\, dx - (n-1) \int \cos (x)^n \,dx \end {align*}
The \(\int \cos (x)^n \,dx\) in the RHS above is what is being solved for. Moving it to the LHS gives \begin {align*} \int \cos (x)^n \,dx + (n-1) \int \cos (x)^n \,dx &= \cos (x)^{n-1} \sin (x) + (n-1) \int \cos (x)^{n-2}\, dx \\ n \int \cos (x)^n \,dx &= \cos (x)^{n-1} \sin (x) + (n-1) \int \cos (x)^{n-2}\, dx \end {align*}
Therefore the recusrive formula is \[ \int \cos (x)^n \,dx = \frac {\cos (x)^{n-1} \sin (x)}{n} + \frac {(n-1)}{n} \int \cos (x)^{n-2}\, dx \]
References: