列平均值C.

时间:2017-11-24 07:24:55

标签: c 2d average

我有下一个函数,我想找到N列的平均值,但在完成M行之后我在averages_days数组中输入了错误的输入,任何想法?

int day_max_average(int a[M][N]) {
    int max = 0, day, i, j, averages_days[N], sum = 0,k=0;

    for (i = 0; i < M; i++) {
        for (j = 0; j < N; j++) {
            sum += a[j][i];
            if(j==N-1){
                averages_days[k] = sum / N;
                k++;
            }
        }
        sum = 0;
    }

    for (i = 0; i < N; i++) {
        printf("%d\n\n\n\n\n\n\n", averages_days[i]);
        if (averages_days[i] >= max) {
            max = averages_days[i];
            day = i + 1;
        }
    }

    printf("H %d (%d.2) \n", day, max);

    return 0;
}

0 个答案:

没有答案