0
#include <stdio.h>
void MatrixProduct(int arr1[][4],int arr2[][4])
{
    int i,j,k;
    int m=sizeof(arr1[0])/sizeof(arr1[0][0]);
    int n=sizeof(arr1)/sizeof(arr1[0]);
    int p=sizeof(arr2[0])/sizeof(arr1[0][0]);
    printf("%d",n); // debug
    int arr3[n][p],s;
    for (i=0;i<n;i++)
    {
        for (j=0;j<p;j++)
        {
            s=0;
            for (k=0;k<m;k++) s=s+arr1[i][k]*arr2[k][j];
            arr3[i][j]=s; 
        }
    }
    for (i=0;i<n;i++)
    {
        for (j=0;j<p;j++)
        {
            printf("%d ",arr3[i][j]);
        }
        printf("\n");
    }
    return;
}


int main()
{
    int mat1[4][4] = { { 1, 1, 1, 1 },
                       { 2, 2, 2, 2 },
                       { 3, 3, 3, 3 },
                       { 4, 4, 4, 4 } };
  
    int mat2[4][4] = { { 1, 1, 1, 1 },
                       { 2, 2, 2, 2 },
                       { 3, 3, 3, 3 },
                       { 4, 4, 4, 4 } };
    MatrixProduct(mat1,mat2);        
    return 1;
}

The above code did not show any output.

In order to find it i put printf statement at line 8. And I got value of n as zero. I checked number of rows code on internet, and it is same as mine. why then I am getting value of n as zero?

0 Answers0