Hi all! would like some help, hopefully someone can enlighten me.
My program has for input a 2d array where the number of rows and columns is decided by the user.

So in the code below, the matrix A is the input matrix and the matrix Q is the matrix to be calculated with the function maqr.
however, as i'm reusing the matrix A as a 1d array in the function maqr, i'm not too sure how to declare the arrays in his function.
Any help will be apreciated!

void main(void)

{
    extern int maqr();
    int i, j;                  /* Loop counter                   */
    int w; 
    int R,C;                   /* Order of Matrix                */
    double**A;             /* Matrix                      */
    double**Q;
    

    printf("Please enter rows of Matrix  A \n"); 
    scanf("%d",&R);
    printf("Please enter columns of Matrix  A \n";
    scanf("%d",&C);
    
   maqr(A,R,C,Q)
   
   A = (double **) malloc(sizeof(double *) * R);
        for(i = 0; i < R; i++)
        {
                A[i] = (double *) malloc(sizeof(double) * C);
        }

   Q = (double **) malloc(sizeof(double *) * R);
        for(i = 0; i < R; i++)
        {
                Q[i] = (double *) malloc(sizeof(double) * R);
        } 

int maqr(a,m,n,q)
  int m,n;
  double a[];
  double q[];
tux4life commented: Used code tags on first post :) +1

Declare maqr() like this:

int maqr(double* a[], int m, int n, double* q[])
{
    // and access the elements of a and q like this:
    double x = *a[0];
}

i believe you will want to call the maqr() function after you've allocated the memory sizes.

also, remember to always use "free" after you're done with the allocated arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.