I am implementing Strassen's matrix multiplication algorithm as a part of an assignment. I have coded it correctly but I don't know why it is giving segmentation fault. I have called strassen() as strassen(0,n,0,n); in main. n is a number given by user which is power of two and it is the maximum size of the matrix (2D Array). It is not giving segfault for n=4 but for n=8,16,32, it is giving segfaults. Code is as given below.
void strassen(int p, int q, int r, int s)
{
int p1,p2,p3,p4,p5,p6,p7;
if(((q-p) == 2)&&((s-r) == 2))
{
p1 = ((a[p][r] + a[p+1][r+1])*(b[p][r] + b[p+1][r+1]));
p2 = ((a[p+1][r] + a[p+1][r+1])*b[p][r]);
p3 = (a[p][r]*(b[p][r+1] - b[p+1][r+1]));
p4 = (a[p+1][r+1]*(b[p+1][r] - b[p][r]));
p5 = ((a[p][r] + a[p][r+1])*b[p+1][r+1]);
p6 = ((a[p+1][r] - a[p][r])*(b[p][r] +b[p][r+1]));
p7 = ((a[p][r+1] - a[p+1][r+1])*(b[p+1][r] + b[p+1][r+1]));
c[p][r] = p1 + p4 - p5 + p7;
c[p][r+1] = p3 + p5;
c[p+1][r] = p2 + p4;
c[p+1][r+1] = p1 + p3 - p2 + p6;
}
else
{
strassen(p, q/2, r, s/2);
strassen(p, q/2, s/2, s);
strassen(q/2, q, r, s/2);
strassen(q/2, q, s/2, s);
}
}