nrows: number of rows
    ncols: number of columns

    int **arra = (int **)malloc( sizeof(int*) * nrows );
    int *ar = (int *)malloc( sizeof(int) * nrows * ncols );
    for( int a = 0; a < nrows; a ++ ) {
        arra[a] = ar + ncols * a;
    }

    now index of array i and j can be accessed as arra[i][j]


On Friday, June 29, 2012 4:46:18 PM UTC+5:30, rahul r. srivastava wrote:
>
> implement a 2d matrix using only 2 mallocs.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/Pr2cEtta_LsJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to