코딩/Language Coder
161 : 배열2 - 형성평가2
pikapika
2018. 6. 28. 16:58
학생들의 점수를 입력을 받다가 0이 입력되면 그 때까지 입력받은 점수를 10점 단위로 구분하여 점수대별 학생 수를 출력하는 프로그램을 작성하시오. (1명도 없는 점수는 출력하지 않는다.)학생은 최대 100명이하이다.
![]() 63 80 95 100 46 64 88 0 |
![]() 100 : 1 person 90 : 1 person 80 : 2 person 60 : 2 person 40 : 1 person |
[코드]
#include <stdio.h>
int main() {
int arr[11] = { 0 };
int score = 1, i;
while (1) {
scanf("%d", &score);
if (score == 0)
break;
arr[score / 10]++;
}
for (i = 10; i >= 0; i--) {
if (arr[i] != 0) {
printf("%d : %d person \n", i * 10, arr[i]);
}
}
return 0;
}