Solution #1: Here is the code,
#include#include int** alloc2d(int row, int col) { int i; int** ptr = NULL; ptr = (int**)malloc(row * sizeof(int*)); for(i=0; i< row; i++) ptr[i] = (int*)malloc(col * sizeof(int)); return ptr; } int main() { int** arr = alloc2d(5, 10); int i,j; for(i=0; i<5; i++) for(j=0; j<10; j++) arr[i][j] = i*j; for(i=0; i<5; i++) { for(j=0; j<10; j++) { printf("%d\t",arr[i][j]); } printf("\n"); } return 0; }
No comments:
Post a Comment