This code suppose to check if in every row and column every number appears only once.

It only succeeds sometimes....

Thanks...

Code:#include <stdio.h> #define NUM 3 int main() { int i,j,flag=1,l ; int mat[NUM][NUM] ; printf("please enter %d*%d matrice: \n" ,NUM ,NUM); for (i=0 ; i<NUM ; i++) for(j=0 ; j<=NUM ; j++) scanf("%d" ,&(mat[i][j])); for (j=0 ; j<NUM && flag!=0; j++) for(i=0; i<NUM && flag!=0; i++) for(l=(i+1);l<NUM && flag!=0 ;l++) if (mat[i][j]!=mat[i+l][j]) flag=1; else flag=0; for (i=0 ; i<NUM && flag!=0 ; i++) for(j=0 ; j<NUM && flag!=0; j++) for(l=(j+1) ; l<NUM && flag!=0; l++) if(mat[i][j]!=mat[i][j+l]) flag=1; else flag=0; if (flag==1) printf("YES\n"); else printf("NO\n"); system("pause"); return 0; }