arr1 = (int *)malloc(sizeof(int) * ncols);    // memory allocated for 1st
row
arr2 = (int **)malloc(sizeof(arr1) * nrows);

I haven't tried it.So,please correct me if i am wrong

On Mon, Jul 2, 2012 at 12:55 PM, Rishabh Agarwal <rishabh...@gmail.com>wrote:

>
>     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.
>



-- 
Abhishek Sharma
Under-Graduate Student,
PEC University of Technology

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
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