#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int r,c,**m,i,j;
clrscr();
printf("\nEnter the no. of rows :");
scanf("%d",&r);
printf("\nEnter the no. of columns :");
scanf("%d",&c);
m=(int**)malloc(r*sizeof(int)); // Allocate memory dynamically for row
for(i=0;i<r;i++)
{
m[i]=(int*)malloc(c*sizeof(int)); // Allocate memory dynamically for column
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("\nEnter elements:");
scanf("%d",&m[i][j]);
}
}
//To display 2D array
printf("\n2D Table is:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
getch();
}
0 Comments