2017.12 程序设计基础月考(期末模拟)

H. 零元素占比

单点时限: 1.0 sec

内存限制: 256 MB

计算一个由整数组成的两维数组中值为 $0$ 的元素的占比 (值的范围为 $[0,1]$)。数组由 $n$ 行组成,每行有 $m$ 个元素 ($1 \le n,m \le 100$)。

#include <stdio.h>

#define M 100

double Ratio(int (*p)[M], int n, int m)
/* PreCondition: 
 p points to a two-dimensional array with n lines and m integers in each line
    PostCondition: array is sorted satisfying to the specification
*/

{

}

int main() {
    int a[100][M], m, n, i, j;
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    printf("%.9f\n", Ratio(a, n, m));
    return 0;
}

样例

Input
2 2
1 0
0 1
Output
0.500000000