0
const int v1=16;
const int v2=16;
const int u1=4;
const int u2=4;

void display(int a[u1][u2],int u1,int u2);
void calculate(int a[v1][v2],int v1,int v2,int,int,int,int);
int main()
{
    int a[16][16];
    clrscr();
    for(int i=0;i<16;i++)
    for(int j=0;j<16;j++)
    {
      cout<<"enter element at position"<<i<<j<<":";
      cin>>a[i][j];
    }
    cout<<"\n";
    calculate(a,16,16,0,3,0,3);
    calculate(a,16,16,0,3,4,7);
    calculate(a,16,16,0,3,8,11);
    calculate(a,16,16,0,3,12,15);
    calculate(a,16,16,4,7,0,3);
    calculate(a,16,16,4,7,4,7);
    calculate(a,16,16,4,7,8,11);
    calculate(a,16,16,4,7,12,15);
    calculate(a,16,16,8,11,0,3);
    calculate(a,16,16,8,11,4,7);
    calculate(a,16,16,8,11,8,11);
    calculate(a,16,16,8,11,12,15);
    calculate(a,16,16,12,15,0,3);
    calculate(a,16,16,12,15,4,7);
    calculate(a,16,16,12,15,8,11);
    calculate(a,16,16,12,15,12,15);
    getch();
    return 0;
}

void calculate(int **a,int n,int m,int il,int iu,int jl,int ju)
{
    int q[4][4],i0=0,j0=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i>=il && i<=iu && j<=ju && j>=jl)
            {
                q[i0][j0]=a[i][j];
                if(j==ju)
                {
                    i0++;
                    j0=0;
                }
                else
                {
                    j0++;
                }
            }
        }
    }
    display(q,u1,u2);
}

The remaning of the code is given below in comments(i.e the display function) whenever I run this in turbo C++ it says

Linking error: undefined symbol display(int a[4]near*,int,int) Linking error: undefined symbol calculate(int a[16]near*,int,int,int,int,int,int)

Please help by letting me know why and what is the solution?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
  • void display(int **a,int n,int m) {for(int i=0;i – Leena Bhadra Feb 20 '13 at 12:31
  • 1
    Two things. 1) Don't post code in the comments, it's unreadable. Instead edit your question with the new information. 2) Where exactly is `display` defined? – StoryTeller - Unslander Monica Feb 20 '13 at 12:52
  • Also note that your prototype for `calculate()` does not match the implementation. (and neither does `display()`, by the looks of it) – JasonD Feb 20 '13 at 13:00
  • 1
    One problem is that `int a[v1][v2]` and `int **a` are totally different types. If you compile this as C++, it sees two different `calculate` functions in your code. Please see [Passing 2D arrays](http://stackoverflow.com/questions/3911400/passing-2d-arrays?lq=1) for some options on parameter passing. – Bo Persson Feb 20 '13 at 13:17

1 Answers1

1

This will compile.

const int v1=16;
const int v2=16;
const int u1=4;
const int u2=4;

void display(int a[u1][u2],int u1,int u2);
void calculate(int a[v1][v2],int v1,int v2,int,int,int,int);
int main()
{
    int a[16][16];
    clrscr();
    for(int i=0;i<16;i++)
    for(int j=0;j<16;j++)
    {
      cout<<"enter element at position"<<i<<j<<":";
      cin>>a[i][j];
    }
    cout<<"\n";
    calculate(a,16,16,0,3,0,3);
    calculate(a,16,16,0,3,4,7);
    calculate(a,16,16,0,3,8,11);
    calculate(a,16,16,0,3,12,15);
    calculate(a,16,16,4,7,0,3);
    calculate(a,16,16,4,7,4,7);
    calculate(a,16,16,4,7,8,11);
    calculate(a,16,16,4,7,12,15);
    calculate(a,16,16,8,11,0,3);
    calculate(a,16,16,8,11,4,7);
    calculate(a,16,16,8,11,8,11);
    calculate(a,16,16,8,11,12,15);
    calculate(a,16,16,12,15,0,3);
    calculate(a,16,16,12,15,4,7);
    calculate(a,16,16,12,15,8,11);
    calculate(a,16,16,12,15,12,15);
    getch();
    return 0;
}

void calculate(int a[v1][v2],int n,int m,int il,int iu,int jl,int ju)
{
    int q[4][4],i0=0,j0=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i>=il && i<=iu && j<=ju && j>=jl)
            {
                q[i0][j0]=a[i][j];
                if(j==ju)
                {
                    i0++;
                    j0=0;
                }
                else
                {
                    j0++;
                }
            }
        }
    }
    display(q,u1,u2);
}

void display(int a[u1][u2],int n,int m)
{
     for(int i=0;i<n;i++)
     {
           for(int j=0;j<m;j++)
                 cout<<a[i][j]<<setw(6);
           cout<<"\n"; 
     }
}

Good Luck.

Quentin Perez
  • 2,833
  • 20
  • 22