我已经编写了这段代码,但我不知道为什么它会因5 3输入而失败.当我给出3 5它工作正常.在每种情况下,如果第二个数字更大,它有效,但为什么呢?我已经用malloc尝试过了.我正在使用Windows 7,代码块10.05
#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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |