Question: ```
 #include<stdio.h>
 int findMax(int **a,int r,int c);
 int main()
 {
  int a[10][10],i,j,max,r,c;
  printf("Enter the number of rows in the matrix\n");
  scanf("%d",&r);
  printf("Enter the number of columns in the matrix\n");
  scanf("%d",&c);
  printf("Enter the elements in the matrix\n");
  for(i=1;i<=r;i++)
  {  for(j=1;j<=c;j++)
     scanf("%d",&[i][j]);
  }
  printf("The matrix is\n");
  for(i=1;i<=r;i++)
  { for(j=1;j<=c;j++)
    scanf("%d",&a[i][j]);
  }printf("\n");}
  max=findMax((int **)a,r,c);
  printf("The maximum elements in the matrix is %d\n",max);
  return 0;
  }
  int findMax(int **a,int r,int c)
  { 
    int t,i,j;
    t=a[1][1];
    for(i=1;i<r;i++)
    { for(j=1;j<c;j++)
    { if(a[i][j]>t)
        t=a[i][j];
    }
    }
   return (t);
  }

```

Here I attached my coding, I need to find the maximum element present in the matrix using function, I am doing the coding, calling function is not executed, I don't know why, Help me to figure it out.

Answer: 
This code snippet works for you.

```
printf("Enter the elements in the matrix\n");
   for(i=0;i<m;i++){
      a[i]=malloc(sizeof(int)*c);
   for(j=0;j<n;j++)
      scanf("%d", &a[i][j]);
 }

```

Then your function call **max=findMax(a,r,c);** will work.
```
#include<stdio.h>
#include<stdlib.h>
int findMax(int **a,int m,int n)
{
    int i,j,larg;
    larg=a[0][0];
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if(larg<a[i][j])
                larg=a[i][j];
        }
    }
    return larg;
}
int main()
{
    int m,n,i,j,larg;
    printf("Enter the number of rows in the matrix\n");
    scanf("%d",&m);
    printf("Enter the number of columns in the matrix\n");
    scanf("%d",&n);
    printf("Enter the elements in the matrix\n");
    int **a=(int**)malloc(m*sizeof(int *));
    for(i=0;i<m;i++)
        a[i]=(int *)malloc(n*sizeof(int));
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            scanf("%d\n",&a[i][j]);
    larg=findMax(a,m,n);
    printf("The matrix is\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }
    printf("The maximum element in the matrix is %d\n",larg);
    return 0;
}

```