I have a big problem when I try to compare two matrix. Every time when I run the program it prints and sets the two matrix with the same values. However you can see in the code below, I have put 2 different matrix with random numbers but It prints always the same numbers in the two matrix... Where is the fail?
#include <stdio.h>
#include <time.h>
void further(int matrix[][3]);
void check(int mat[][3], int another[][3]);
int main (){
int mat[3][3];
int another[3][3];
further(mat);
further(another);
check(mat,another);
system("pause");
return 0;
}
void further(int matrix[][3]){
srand(time(NULL));
int i,j,aux;
for(i=0; i<3; i++){
for(j=0; j<3;j++){
aux=rand()%10;
matrix[i][j]=aux;
}
}
}
void check(int mat[][3], int another[][3]){
int i,j,aux;
aux = 0;
for(i=0; i<3 && aux == 0; i++){
for(j=0; j<3 && aux == 0; j++){
if(mat[i][j] != another[i][j]){
aux = 1;
}
}
}
for(i=0; i<3; i++){
for(j=0; j<3; j++){
printf("%i ",mat[i][j]);
}
printf("\n");
}
printf("\n");
for(i=0; i<3; i++){
for(j=0; j<3; j++){
printf("%i ",another[i][j]);
}
printf("\n");
}
if(aux==0){
printf("Those matrix are equal.\n\n");
}
else{
printf("Those matrix are NOT equal.\n\n");
}
}