If $A^2=A$ then prove that $\textrm{tr}(A)=\textrm{rank}(A)$. Let $A\not=I_n$ be an $n\times n$ matrix such that $A^2=A$ , where $I_n$ is the identity matrix of order $n$.  Then prove that ,
(A) $\textrm{tr}(A)=\textrm{rank}(A)$.
(B) $\textrm{rank}(A)+\textrm{rank}(I_n-A)=n$
I found by example that these hold, but I am unable to prove them.

The given condition $A^{2}=A$ says that the matrix is idempotent and so diagonalizable and hence rank is same as the number of eigen values $1$(with repetition ) which is the same as trace of $A.$ For second part use it $$|rank(A)-rank(B)|\leq rank(A+B)\leq n.$$
