P186. Program to allocate dynamic memory for integer 2D array, scan it and print it.
#include<stdio.h>
#include<stdlib.h>
void
main()
{
int
**p,r,c,i,j;
printf("Enter
number of rows : ");
scanf("%d",&r);
printf("Enter
number of coloums : ");
scanf("%d",&c);
p=malloc(sizeof(int*)*r);
for(i=0;i<r;i++)
p[i]=malloc(sizeof(int)*c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&p[i][j]);
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("%d ",p[i][j]);
printf("\n");
}
}
Comments
Post a Comment