-
STUDENT
#include <stdio.h>
#define STUDENT 20
#define SCORE_MIN 0
#define SCORE_MAX 100void inputscore(int score[STUDENT], int i);
int scoremax(int score[STUDENT], int *max, int j);
int scoremin(int score[STUDENT], int *min, int k);
float scoreavg(int score[STUDENT], float *avg, float scoresum, int l);
int outputscore(int score[STUDENT], int max, int min, float avg);void main()
{
int score[STUDENT];
int max=0, min=0;
float avg=0;
float scoresum=0;
int i=0, j=0, k=0, l=0;inputscore(score, i);
scoremax(score, &max, j);
scoremin(score, &min, k);
scoreavg(score, &avg, scoresum, l);
outputscore(score, max, min, avg);
}void inputscore(int score[STUDENT], int i)
{
int tmp, fail=0;for(i=0; i<STUDENT; i++)
{
printf("input score : ");
scanf("%d", &tmp);if(tmp>SCORE_MAX || tmp<SCORE_MIN)
fail = 1;while(fail == 1)
{
printf("wrong input! score must be 0~100.\ninput score : ");
scanf("%d", &tmp);
if( (tmp<=SCORE_MAX) && (tmp>=SCORE_MIN) )
fail = 0;
}score[i] = tmp;
}
}int scoremax(int score[STUDENT], int *max, int j)
{
*max = score[0];
for(j=0; j<STUDENT; j++)
{
if(score[j]>*max)
*max = score[j];
}return *max;
}int scoremin(int score[STUDENT], int *min, int k)
{
*min = score[0];
for(k=0; k<STUDENT; k++)
{
if(score[k]<*min)
*min = score[k];
}return *min;
}float scoreavg(int score[STUDENT], float *avg, float scoresum, int l)
{
for(l=0; l<STUDENT; l++)
scoresum += score[l];*avg = (float)(scoresum/STUDENT);
return *avg;
}int outputscore(int score[STUDENT], int max, int min, float avg)
{
int m;for(m=0; m<STUDENT; m++)
printf("%d ", score[m]);
printf("\n");printf("max : %d\n", max);
printf("min : %d\n", min);
printf("avg : %.2f\n", avg);return 0;
}