Artificial intelligent assistant

How to show $\text{rank}(p)=\text{trace}(p)$ for every projector $p$ defined on $\mathbb{R}^n$? I know this is an old question and there are several answers for this using eigenvalues and matrix factorization but they have not taught in my matrix analysis course yet. Therefore, my question would be a different proof for the following: $$\text{rank}(p)=\text{trace}(p)$$ where $p$ is an $n \times n$ matrix. The only thing that we are allowed to use is $p^2=p$ and the fact that $\text{trace}(AB)=\text{trace}(BA)=$ where $A,B$ are conformable matrices. Please notice what I have asked before answering the question.

Consider a rank-factorization $p = cf$ where $f:\Bbb R^n \to \Bbb R^r$ and $c:\Bbb R^r \to \Bbb R^n$, where $r = \operatorname{rank}(p)$, $c$ is injective, and $f$ is surjective. We note that $$ p^2 = p \implies cfcf = cf. $$ That is, we have $c(fc)f = c(\operatorname{id}_{\Bbb R^r})f$. Because $f$ has a right-inverse and $c$ has a left-inverse, we may conclude from the above that $fc = \operatorname{id}_{\Bbb R^r}$. It follows that $$ \operatorname{trace}(p) = \operatorname{trace}(cf) = \operatorname{trace}(fc) = \operatorname{trace}(\operatorname{id}_{\Bbb R^r}) = r $$ which was the desired result.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 4f32e86160dc1c6229ffc826bba18d62