/* a11-1-4.c */
#include <stdio.h>
#define N 100	/* 配列要素数 */

int main(void)
{
	FILE *fp;
	int i, n = 0, mode, count, maxcount;
	int array[N];

	if( (fp = fopen("data.txt", "r") ) == NULL) {
		printf("File open error.\n");
		return 1;
	}

	while (fscanf(fp, "%d", &array[n]) == 1) {
		n++;
		if (n >= N) {
			printf("データ数が%dを超えました。\n", N);
			fclose(fp);
			return 1;
		}
	}

	count = maxcount = 1;
	mode = array[0];
	for (i = 1; i < n; i++) {
		if (array[i - 1] == array[i]) {
			count++;
		}
		else {
			count = 1;
		}
		if (count > maxcount) {
			maxcount = count;
			mode = array[i - 1];
		}
	}
	printf("メジアン = %d\n", array[n / 2]);
	printf("モード = %d\n", mode);

	fclose(fp);

	return 0;
}
