당신은 3 개 주요 문제를했습니다 :
1 Jongware 그의 의견에 말한다 것처럼 printf
이 아닌 외부 루프 내부에 있어야한다.
2#include <stido.h>
는 (이 경우에 우리가 일반적으로 row++
또는 ++row
사용) row = row + 1
, 또는 row += 1
, 또는 row++
, 또는 ++row
을해야 #include <stdio.h>
3.row +1
있어, 존재하지 않습니다. 물론 차 col
에 대해 동일한 작업을 수행해야합니다
을 수행합니다.practice_array
및 i
은 쓸모가 없습니다.
b.printf
에 \n
을 잊어 버린 것 같습니다.
나는 코드를 수정 + I는 최소, 최대, 평균 값 추가 :
#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);
}
당신을 'print' 명령을'row'와'col'을위한 루프 안에 넣어야합니다; 또는 먼저 배열을 계산하고 * 인쇄 한 다음 인쇄하려면 루프를 반복하여 인쇄하십시오. – usr2564301
그리고'#include'이 존재하지 않습니다.'#include '입니다. –
Biduleohm
배열이 잘못 인쇄되고 있습니다. 누더기 추가가 중단되지 않습니다. 제발 도와주세요. – user3479702