Я написал этот код, но я не знаю, почему он терпит неудачу с входом 5 3. Когда я даю 3 5, он отлично работает. В каждом случае, если второе число больше, оно работает, но почему? Я уже пробовал это с malloc. Я использую Windows 7, блоки кода 10,05Почему не работает матрица с 5,3, но 3,5?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int **matr;
int row, col, i, j;
scanf("%d", &row); //number of rows
scanf("%d", &col); //number of cols
matr = calloc(col, sizeof(int*)); //creating cols
for(i = 0; i < col; i++)
{
matr[i] = calloc(row, sizeof(int)); //in every col i create an array with the size of row
}
for(j = 0; j < row; j++)
{
for(i = 0; i < col; i++)
{
matr[j][i] = 10; //fill the matrix with number 10
}
}
printf("Matrix is ready\n");
for(j = 0; j < row; j++) //printing the matrix
{
for(i = 0; i < col; i++)
{
printf("%d ", matr[j][i]);
}
printf("\n");
}
return 0;
}
Какую ошибку вы получаете? – Abraham
'matr = calloc (col, sizeof (int *));' -> 'matr = calloc (строка, sizeof (int *));', 'for (i = 0; i