void sort(int [],int);
This is how I usually use a single dimensional array(i.e: int []
) inside a function declaration statement for programs like sorting and it works fine without any problem
But for my matrix addition program when I use a two dimensional array(i.e:int [][]
) inside a function declaration statement with the similar format void mat(int [][],int [][],int ,int);
Iam getting some error messages like:-
1.multidimensional array must have bounds for all dimensions except the first.
2.invalid conversion from 'int (*)[10]' to 'int' [-fpermissive].
So my question is how to write a two dimensional array inside a function declaration statement.
Below I have attached my full Matrix addition program using functions:-
#include<stdio.h>
void mat(int [][],int [][],int ,int);
int main()
{
int a[10][10],b[10][10],m,n,i,j;
printf("Enter the rows and coloumns: ");
scanf("%d %d",&m,&n);
printf("\nEnter the elements of 1st Matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the elements of the 2nd Matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
mat(a,b,m,n);
}
void mat(int a[10][10],int b[10][10],int m,int n)
{
int i,j,c[10][10];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nThe addition of the 2 Matrix is :");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d",c[i][j]);
}
}