Dynamic 2D array:

#include
#include
#include

int main()
{
int r,c;
clrscr();
printf("Enter the size of the 2d array in (RXC) format :");
scanf("%dx%d",&r,&c);
int *data=(int *)malloc(r*c*sizeof(int));
int index=1;

// Taking Input from the user in array
for(int i=0;i {
for(int j=0;j {
index=r;
index*=i;
index+=j;
printf("Enter number : %d -> ",index);
scanf("%d",(data+index));
}
}

//Print the values from the array.
for(i=0;i {
for(int j=0;j {
index=r;
index*=i;
index+=j;
printf("\nValue No. %d stored in Array(%d,%d) is %d",index,i,j,*(data+index));
}
}
getch();

}

Comments