clear % A=[2 4 5; 8 1 7; 3 6 0]; B=reshape(A',1,9); B(end)=[]; k=length(B); numinv=0; for i=1:k-1 for j=i+1:k if B(i)>B(j) numinv=numinv+1; end end end numinv if mod(numinv,2)==0 disp('Ima resenja.') else disp('Nema resenja.') end