[ad_1]

I am writing a C program to add 2 matrices.

But meanwhile, I’ve encountered this error, more precisely a problem, as I’ve got no error message on compiling.

I have no idea why this code isn’t working.

```
#include <stdio.h>
int m, n;
int add(int A[m][n], int B[m][n]);
int main()
{
int a, b, A[a][b], B[a][b];
printf("Enter the order : ");
scanf("%d%d", &a, &b);
m = a;
n = b;
printf("Enter the 1st matrix : \n");
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
scanf("%d", &A[i][j]);
}
}
printf("Enter the 2nd matrix : \n");
for (int i = 0; i < a; i++)
{
for (int j = 0; j < b; j++)
{
scanf("%d", &B[i][j]);
}
}
add(A, B);
return 0;
}
int add(int A[m][n],int B[m][n])
{
printf("Resultant Matrix : \n");
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
printf("%d ", A[i][j] + B[i][j]);
}
printf("\n");
}
return 0;
}
```

I’ve come to know that the values I’ve entered for the 2nd matrix were copied to the 1st one too while debugging my code, But I’m totally unaware of ‘why is that’.

I am sure enough that something is wrong with my code (may be at another line too), But I particularly want to know how to perfectly take the 2 array inputs without any fallacy.

Some please help!

[ad_2]