Hi,
The below program does some operations on multiple matrices. For reading these multiple matrices, am using a function readmat().
Code:
#include<stdio.h>
void readmat(int *a)
{
int i,j;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",a[i][j]);
}
void printmat(int *a)
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
printf("\t%d",*a[i][j]);
printf("\n");
}
}
int main()
{
int a[2][2], b[2][2], c[2][2];
printf("\n Enter Matrix A:\n");
readmat(&a);
printf("\n Enter Matrix B:\n");
readmat(&b]);
printf("\n\n Matrix A: \n");
printmat(&a);
printf("\n\m Matrix B: \n");
printmat(&b);
return 0;
}
This program compiles well. But fails during runtime after reading 1st element of the array. I guess, the problem is here with passing the uninitialized 2d array to function by reference. Can someone show me how to do this?
-
Thanks