rendered paste body#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, cols, rows;
char buffer[80];
int **mat;
printf("Cols: ");
fgets(buffer, sizeof(buffer), stdin);
cols = atoi(buffer);
printf("Rows: ");
fgets(buffer, sizeof(buffer), stdin);
rows = atoi(buffer);
/* allocate 2d matrix */
mat = malloc(cols * sizeof(int*));
for(i = 0; i < cols; i++)
mat[i] = malloc(rows * sizeof(int));
/* ask the user for it's values */
for (i = 0; i < cols; i++)
for(j = 0; j < rows; j++) {
printf("Value [%d][%d]: ", i, j);
fgets(buffer, sizeof(buffer), stdin);
mat[i][j] = atoi(buffer);
}
/* print values out */
printf("\nPrinting table out:\n");
for (i = 0; i < cols; i++) {
for(j = 0; j < rows; j++) {
printf("%d ", mat[i][j]);
}
printf("\n");
}
getche();
return 0;
}