i'm woundering why this code is not working, I want to generate random numbers from 1-10 and insert in matrice and to print them. Matrice is 3x3 dimension:
int main(){
srand(1);
int i,j;
int mat[3][3];
for(i<0;i<3;i++){
for(j=0;j<3;j++){
mat[i][j]=rand()%9+1;
}
}
for(i<0;i<3;i++){
for(j=0;j<3;j++){
printf("%2d",mat[i][j]);
}
printf("\n");
}
return 0;
}
答案 0 :(得分:1)
The problem is in
for(i<0;i<3;i++){
^^^
it should be
for(i=0;i<3;i++){
Otherwise, you end up using uninitialized local variable i
value, which leads to undefined behavior.