#include<stdio.h>
#include<stdlib.h>
void main()
{
int **tab,m,n,i,j;
clrscr();
printf("Enter no.of rows & cols:");
scanf("%d %d",&m,&n);
tab = (int **)malloc(m*sizeof(int *));
for(i=0;i<m;i++)
{
tab[i] = (int *)malloc(n*sizeof(int));
}
printf("Enter elements of table:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("[%d][%d]=",i,j);
scanf("%d",&tab[i][j]);
}
}
printf("Elements of table:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%4d",tab[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
free(tab[i]);
free(tab);
tab = NULL;
printf("Table earsed successfully.");
}
Output:
Enter no.of rows & cols: 5 5
Enter elements of table:
[0][0]=11 12 13 14 15
[0][1]=[0][2]=[0][3]=[0][4]=[1][0]=
[0][1]=[0][2]=[0][3]=[0][4]=[1][0]=
[1][1]=[1][2]=[1][3]=[1][4]=[2][0]=
[2][1]=[2][2]=[2][3]=[2][4]=
[3][0]=[3][1]=[3][2]=[3][3]=[3][4]=
[4][0]=[4][1]=[4][2]=[4][3]=[4][4]=
Elements of table:
11 12 13 14 15
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Table earsed successfully.