General Protection Error in C++ code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onkarbulbule
    New Member
    • Jan 2013
    • 2

    General Protection Error in C++ code

    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();
    }
    Last edited by Banfa; Jan 24 '13, 03:27 PM. Reason: added code tags round the code
  • onkarbulbule
    New Member
    • Jan 2013
    • 2

    #2
    PS -
    The error is in the for loop probably in the line -
    b[i][j] = b[j][i] = b[5-i][j] = b[j][5-i] = 0;
    Please help!

    Comment

    • Gobi Sakthivel
      New Member
      • Jan 2013
      • 26

      #3
      Can u explain what is meant by convolution, and give some sample input and output to make it clear.

      Comment

      • Anas Mosaad
        New Member
        • Jan 2013
        • 185

        #4
        Convolution is a term used in pattern matching to determine the overlaps between two input matrices. For example, if you are searching for letter A in a photo, you would multiply the A matrix in different pieces from the photo matrix until you detect the overlaps (i.e. matches). Hope it's clear now.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Trying out your code unmodified and inputting 1 for all items produces a result with no crash.

          Visual inspection of the code shows no reason for a crash to happen.

          Without further information I am not sure there is much more we can do.

          Comment

          Working...