Mar

24

#include<stdio.h>
#include<stdlib.h>
void main(){
int row,col,i,j;
int *ptr;
printf(“Enter How many Rows you want in 2D Array: “);
scanf(“%d”,&row);
printf(“Enter How many Cols you want in 2D Array: “);
scanf(“%d”,&col);
ptr=(int*) malloc(row*col*sizeof(int));
for(i=0;i<row;i++){
printf(“Enter %d values for row %d:\n”,col,i+1);
for(j=0;j<col;j++){
scanf(“%d”,(ptr+i*col+j));
}
}
printf(“\nEntered Values are:\n”);
for(i=0;i<row;i++){
for(j=0;j<col;j++){
printf(“%d\t”,*(ptr+i*col+j));
}
printf(“\n\n”);
}
free(ptr);
}


Leave a Reply