#include<stdio.h>
#include<conio.h>
# define rows [3]
# define cols [3]
void input(int arr2d[][cols]);
void print (int arr2d[][cols]);
void add (int mat1[][cols],int mat2[][cols],int result[][cols]);
int result[][cols];
void main(void)
{ int mat1[rows][cols],mat2[rows][cols],ans[rows][cols];
input(mat1);
input(mat2);
add(mat1,mat2,ans);
print(ans);
}
void input(int arr2d[][cols])
{
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
{printf("enter element [%d] [%d]",i,j);
scanf("%d",&arr2d[i][j]);
}
}
void print(int arr2d[][cols]
{
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
printf("element [%d][%d]=%d",i,j,arr2d[i][j];
}
void add(int num1[][cols],int mat2[][cols],int result[][cols];
{
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
result[i][j]=mat1[i][j]+mat2[i][j];
}
views:
42answers:
1
A:
Firstly, please indent your code. It is not hard and really helps for readability. Next, you probably meant:
#define rows 3
#define cols 3
Next, this line is wrong:
printf("element [%d][%d]=%d",i,j,arr2d[i][j]; // you need a )
and
void add(int num1[][cols],int mat2[][cols],int result[][cols]; // same problem
There are probably other problems in your code, but just make these corrections for now. Also, can you actually post the compiler errors you are getting.
Alexander Rafferty
2010-09-30 13:09:01