Last active
March 6, 2021 04:27
-
-
Save KeitetsuWorks/be468f62e95ac04ecbf428f441cbc801 to your computer and use it in GitHub Desktop.
試験の点数score[]の分布を求め、それを棒グラフ状に表示する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file q11182261791.c | |
* @brief 試験の点数score[]の分布を求め、それを棒グラフ状に表示する | |
* @author Keitetsu | |
* @date 2017/11/19 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define EXAMINEES_NUM 100 /**< 受験者数 */ | |
#define SCORE_MAX 100 /**< 最高点数 */ | |
int main(void) | |
{ | |
int score[EXAMINEES_NUM]; | |
int dist[11]; | |
int i, j, distIndex; | |
printf("点数を初期化しています ... \n"); | |
srand((unsigned int)time(NULL)); | |
for (i = 0; i < EXAMINEES_NUM; i++) { | |
score[i] = rand() % (SCORE_MAX + 1); | |
printf("score[%3d] = %3d\n", i, score[i]); | |
} | |
printf(" ... 完了\n"); | |
printf("分布を初期化しています ... "); | |
for (i = 0; i < 11; i++) { | |
dist[i] = 0; | |
} | |
printf("完了\n"); | |
printf("点数の分布を求めています ... "); | |
for (i = 0; i < EXAMINEES_NUM; i++) { | |
distIndex = score[i] / 10; | |
dist[distIndex]++; | |
} | |
printf("完了\n"); | |
for (i = 0; i < 11; i++) { | |
printf("%3d 点以上 %3d 点未満 ... %3d 名: ", i * 10, (i + 1) * 10, dist[i]); | |
for (j = 0; j < dist[i]; j++) { | |
printf("*"); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment