0

As part my lab test this upcoming Tuesday, we're required to be able to do this question, otherwise we won't be able to do the real exam!

Here is the code :

 * This program finds the range between highest and lowest value of a 2-D array */

#include <stdio.h>

#define NROW 3
#define NCOL 3    

int main(void)
{
    /* declare needed variables or constants, e.g. */

    int ar[NROW][NCOL];
    int number;
    int rows, columns;

    /* prompt for the user to enter nine positive integers to be stored into the array */
    for ( rows = 0 ; rows < 3 ; rows++ )
    {
        for ( columns = 0 ; columns < 3 ; columns++ )
        {
            printf("Please enter 9 numbers " );

            scanf("%d", &number);ar[NROW][NCOL]

            /*store the number temporarily*/
            number = dispArray( ar[NROW][NCOL] )
        }
    }


    /* call the disp_arr(...) function */
    dispArray()

/* call the highest(...) function */


/* call the lowest(...) function */


/* display the range between highest and lowest number


/* Return to the operating system */


}
    void dispArray( a[][] )
    int rows, columns, a[][];

    for ( rows = 0 ; rows < 3 ; rows++ )
    {
        for ( columns = 0 ; columns < 3 ; columns ++ )
        {
            printf( "%d\t", a[][] );
        }
        printf("\n");
    }

    return a[][];

    /* Write a function where a[][] is the 2-D array
    Print the entire array to the screen. */

At the moment I just need to know how to print the array to the screen. My function and the way I call it in the main are obviously wrong.

I'm really bad at functions especially when it comes to passing arguments...which I have no idea what is it too.

Any help would be appreciated! Thanks! Sam

4

2 回答 2

0

您需要进行这些更改

/* call the disp_arr(...) function */
dispArray(ar)    

void dispArray(int a[][] )

然后,该函数dispArray需要在.{}void dispArray(int a[][] )

于 2013-11-10T10:40:03.097 回答
0
  • 首先 dispArray 函数返回 void,因此没有必要将其分配给 number 变量。
  • dispArray 采用二维数组,因此调用应如下所示dispArray(ar);
  • dispArray 签名void dispArray(a[][])应该是void dispArray(int a[][NCOL]),在你将int a[][]参数传递给函数后,不需要在里面创建新的二维数组,a[][]int rows, columns, a[][];
  • 正如 Robin 所说,从 dispArray 返回 a[][] 是没有意义的
  • 你忘了大括号 { ... } 之后void dispArray(int a[][])
于 2013-11-10T10:40:18.547 回答