Let $A$ be an $n\times n$ matrix over real numbers such that $AB=BA,$ for all $n\times n$ matrices $B$ [duplicate]

I was thinking about the following problem:

Let $A$ be an $n\times n$ matrix over real numbers such that $AB=BA,$ for all $n\times n$ matrices $B$.Then which of the following options is correct?

(a)$A$ must be zero,
(b)$A$ must be the identity,
(c)$A$ must be a diagonal matrix,
(d)$A$ must be either $0$ or the identity.

I think the answer will be between $(c)$ and $(d)$. But i am not sure how to get the exact result.Can someone show me the right direction? Thanks in advance for your time.

marked as duplicate by Marc van Leeuwen linear-algebra StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Feb 4 '15 at 8:22

• Others have answered this question, correctly, as (c). But be careful. It is not true that if $A$ is a diagonal matrix, it has this property. It is only true for a specific subset of diagonal matrices. – Thomas Andrews Dec 17 '12 at 14:50

Hint Let $B$ be a diagonal matrix with pairwise disjoint diagonal entries. Then $AB=BA$ implies that $A$ is a diagonal matrix. This is very easy to prove, just write explicitly $AB$ and $BA$.
P.S. The most general thing you can prove about this problem is that $AB=BA$ for all $B$ if and only if $A= cI$.
You can immediately rule out answers (a), (b) and (d) by considering the matrix $A = 2I$, where $I$ is the identity matrix. This leaves (c) as the only option.
To actually prove statement (c), try looking at certain specific matrices $B$. For example, if $B$ is a matrix which has only one non-zero entry, what does the equation $AB=BA$ tell you about $A$?
Only (c) is correct. Just consider $n=2$ and $A=2I$. Then $AB=BA$ for all $2\times 2$ matrix $B$, but $A$ is neither zero nor identity.