您已经3个主要问题:
作为Jongware在他的评论说,printf
应的循环,不在外面里面。
2.#include <stido.h>
不存在,这是#include <stdio.h>
row +1
应row = row + 1
,或row += 1
,或row++
,或者++row
(在这种情况下,我们通常用row++
或++row
)。当然,你需要为col
次做同样的:
一个。practice_array
和i
在这里没用。
b。你可能忘了printf
中的\n
。
我纠正你的代码+我加了最小值,最大值和平均值:
#include <stdio.h>
#include <math.h>
#include <time.h>
#define ROWS_NB 3
#define COLS_NB 5
#define MIN_VAL 1
#define MAX_VAL 10000
int main(void)
{
int array[ROWS_NB][COLS_NB];
int row;
int col;
int val;
int min = MAX_VAL;
int max = MIN_VAL;
int avg = 0;
srand(time(NULL));
for (row = 0; row < ROWS_NB; ++row)
{
for (col = 0; col < COLS_NB; ++col)
{
val = (rand() % (MAX_VAL - MIN_VAL)) + MIN_VAL;
if (val < min)
min = val;
else if (val > max)
max = val;
avg += val;
array[row][col] = val;
//printf("%d ", val);/* uncomment if you want to print the array */
}
//printf("\n");/* uncomment if you want to print the array */
}
avg /= ROWS_NB * COLS_NB;
printf("min: %d\nmax: %d\naverage: %d\n", min, max, avg);
return (0);
}
你需要将'printf'命令放入'row'和'col'的循环中;或者,如果您首先要计算数组并然后*打印它们,请重复循环打印。 – usr2564301
'#include'不存在,它是'#include '。 –
Biduleohm
我的数组打印错误,它不会停止添加nubers,你能帮我吗? – user3479702