0

I am working on a C program that will find the sum of the diagonal elements of a matrix. One function in the program is supposed to print the matrix, but I cannot get the program to compile because of the error listed in the title. The code for the function is as follows

    void print_matrix(int A[10][10], int a)
        {
            int i, j ;
            printf("The matrix entered is\n") ;
            for ( i = 0 ; i < a ; i++)
                { for ( j = 0 ; j < a ; j++)
                   printf("\t%d", A[i][j]) ;
                }
         }

The error reads "expected 'int (*)[10]' but argument is of type 'int'" I have tried to change the parameter to read print_matrix(int (*)[10], int a) and the same error is output. Using print_matrix(int A[][10], int a) also gives the same error. I have been unable to find what I am doing wrong. Any help is appreciated.

4

1 回答 1

1

假设你有你的矩阵:

 int A[10][10] = { ... };

你应该这样调用函数:

 print_matrix( A, 10 );
于 2013-11-07T04:03:31.883 回答