[ create a new paste ] login | about

Link: http://codepad.org/ZbmxjcO2    [ raw code | output | fork ]

C, pasted on May 22:
#include <stdio.h>

int main(void) {
	double height[10], average = 0.0;
	int over160 = 0, under160 = 0;
	int i;
	char c;

	for(i = 0; i < 10; i++) {
		printf("%d人目の身長を150.0~180.0cmで入力[cm] : ", i + 1);
		scanf("%lf", &height[i]);

		if(height[i] < 150.0 || height[i] > 180.0) {
			puts("入力が不正");
			i--;
			while((c = getchar()) != '\n');
			continue;
		}

	}

	for(i = 0; i < 10; i++) {
		if(height[i] < 160.0) { under160++; }
		else { over160++; };
		average += height[i];
	}
	average /= i;

	printf("160cm以上の人数:%d\n", over160);
	printf("160cm未満の人数:%d\n", under160);
	printf("身長の平均値:%.2f\n", average);

	return 0;
}


Output:
1
Timeout


Create a new paste based on this one


Comments: