douglas0421   3년 전

위에거는 cnt값이 변하지 않고 아래는 정상적으로 실행이 됩니다.

jjangman821   3년 전

total 초기화를 안하셨네요.

#include

int main()
{
int c = 0, n = 0, score[1000] = { 0 }, cnt = 0, total = 0;
double avg = 0;
scanf_s("%d", &c);
for (int i = 0; i < c; i++){
scanf_s("%d", &n);
for (int j = 0; j < n; j++){
scanf_s("%d", &score[j]);
total += score[j];
}

avg = (double)total / n;

for (int k = 0; k < n; k++) {
if (score[k] > avg) {
cnt++;
}
}

printf("%.3f\n", ((double)cnt / (double)n) * 100);
cnt = 0; total = 0;
}
return 0;
}

제대로 나옵니다.

douglas0421   3년 전

아 total초기화하는건 왜생각을 못했을까요... 감사합니다

댓글을 작성하려면 로그인해야 합니다.