#include <stdio.h>
#include <stdlib.h>
int main() {
int rows, cols, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);
int matrix = (int )malloc(rows sizeof(int ));
for (i = 0; i < rows; i++) {
matrix[i] = (int )malloc(cols sizeof(int));
}
printf("Enter the elements of the matrix:\n");
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
scanf("%d", &matrix[i][j]);
}
}
printf("The matrix is:\n");
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
for (i = 0; i < rows; i++) {
free(matrix[i]);
}
free(matrix);
return 0;
}