Friday, April 24, 2015

Implement Two Dimentional array with dynamic memory allocation in C Language

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int r=3,c=3;//r=row,c=column
int *arr=(int*)malloc(r*c*sizeof(int));

int i,j;
printf("Enter the elements=");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("\n no=");
scanf("%d",(arr+i*c+j)); //row column operation
}

}
printf("\n output=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("\t%d",*(arr+i*c+j)); // two d array output
}
printf("\n");

}

}

No comments:

Post a Comment