#include <stdio.h>
#include <malloc.h>
#define N 100
int main()
{
int **a, nRow, nCol;
scanf("%d%d", &nRow, &nCol); //Nhap hang vs cot
a = (int**)malloc(nRow * sizeof(int*));
printf("\n\n");
for (int i = 0; i < nRow; i++)
{
a[i] = (int*)malloc(sizeof(int));
for (int j = 0; j < nCol; j++)
{
scanf("%d", a + nCol*i + j); //Nhap phan tu
}
}
printf("\n\n");
for (int i = 0; i < nRow; i++)
{
for (int j = 0; j < nCol; j++)
{
printf("%d ", a[i][j]); //In phan tu
}
printf("\n");
}
free(a);
return 0;
}
Em đang gặp 1 vấn đề ở chỗ scanf phần tử.
Lúc mà em thay scanf("%d", a + nCol*i + j); //Nhap phan tu bằng scanf("%d", &a[ i ][ j ]) , tương tự với printf thì nó lại chạy bình thườn.
Cách khắc phục là j v mn
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?