Hi I am trying to do a program on convolution, that is, multiplying 2 non-multipliable matrices. Here is the code. I even know where I'm getting an error. It's on line 20. Please help me out. Why am I getting this error?
Code:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5], b[10][10], t[20][10][10], res[10][10];
int i, j, k, x;
cout<<"Enter matrix 1 : \n";
for(i=0; i<3; i++)
for(j=0; j<3; j++)
cin>>a[i][j];
cout<<"Enter matrix 2 : \n";
for(i=1; i<5; i++)
for(j=1; j<5; j++)
cin>>b[i][j];
for(i=0, j=0; j<6; j++)
{
b[i][j] = b[j][i] = b[5-i][j] = b[j][5-i] = 0;
}
for(x=0; x<16; x++)
{
res[x/4][x%4]=0;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
t[x][i][j] = 0;
for(k=0; k<3; k++)
{
t[x][i][j] += a[i][k]*b[k+x/4][j+x%4];
}
res[x/4][x%4] += t[x][i][j];
}
}
}
cout<<"The resultant matrix is :\n";
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
cout<<res[i][j]<<" ";
}
cout<<endl;
}
getch();
}
Comment