# calculate meian

of 4

## Content

#include <stdio.h>
#define STUDENTS 100
#define EXAMS 4
int minimum(const int scores[][EXAMS], int pupils, int test );
int maximum(const int scores[][EXAMS], int pupils, int test );
double mean(const int setOfScores[], int test);
void printArray(const scores[][EXAMS], int pupils, int tests);
void median( int setOfScores[], int test );
void bubbleSort( int a[][EXAMS], int, int );
int main(void)
{
int student;
int i, j, pupils, tests;
int studentScores[ STUDENTS][EXAMS];
FILE *infile;
infile = fopen ("data.txt", "r");
fscanf (infile, "%d %d", &pupils, &tests);
for (i=0; i<pupils; i++) {
for (j=0; j<tests; j++) {
fscanf (infile, "%d", &studentScores[i][j]);
}
}
/* output array studentScores */
printf( "The array is:\n");
printArray( studentScores, STUDENTS, EXAMS );
/**************************************************
** determine smallest and largest grade values
*****
**************************************************/
minimum( studentScores, STUDENTS, EXAMS ),
maximum( studentScores, STUDENTS, EXAMS ));
/***************************************************
**** calculate average grade for each student
************************************************/
for (student = 0; student<STUDENTS; student++ ) {
printf( "mean=The average grade for student %d is %.2f\n",
student, mean(studentScores[student], EXAMS));
/**************************************************
******** calculate median for each student **************
*************************************************/
for (student =0; student<STUDENTS; student++) {
printf( "median= %d is %.2f\n",
student, median(studentScores[student], EXAMS));
}
return 0;

}
/***********************************************************************
*********
*******
***********************************************************************/
int minimum( const int scores[][EXAMS], int pupils, int tests )
{
int i; /* student counter */
int j; /* exam counter */
/* loop through rows of scores */
for (i=0; i < pupils; i++) {
/* loop through columns of scores */
for (j=0; j < tests; j++) {
}
}
} /*
}
/**********************************************************
********
*******
*********************************************************/
int maximum( const int scores[][EXAMS], int pupils, int tests)
{
int i;
int j;
/* loop through rows of scores */
for (i=0; i < pupils; i++) {
/* loop through columns of scores */
for (j=0; j < tests; j++) {

}

if (scores[i][j] > highGrade ) {
}

}
}

/******************************************************
*** Determine the average score for a particular student ********
*******************************************************/
double mean( const int setOfScores[], int tests )
{
int i;
int total = 0;

/* total all scores for one student */
for (i=0; i < tests; i++) {
total += setOfScores[i];
}
return (double) total / tests;
}
/******************************************************
********
Print the array
********
******************************************************/
void printArray(const int scores[][EXAMS], int pupils, int tests)
{
int i;
int j;
for (i=0; i<pupils; i++) {
/* output label for row */
printf("\nstudentScores[%d] ", i);
/* output scores for one student */
for (j = 0; j < tests; j++) {
printf( "%-5d", scores[i][j] );
}
}
void median( int setOfScores[], int tests)
{
bubbleSort( studentScores[][EXAMS], int, int); /* sort array */
printf("\n\nThe sorted array is ");
printArray(setOfScores, int tests); /* output sorted array */

}

/*display median element */
printf("\n\nThe median is %d\n\n", scores[][ EXAMS / 2] );
/* end function median */

/*******************************************************
** function that sorts an array with bubble sort algorithm ***
*******************************************************/
void bubbleSort(int studentScores[][EXAMS], int hold, int test)
{
int pass; /* pass counter */
int i, j;
/* comparism counter */
int hold; /* temporary location used to swap elements */
/* loop to control number of passes */
for (pass = 1; pass < tests; pass++)

{

/* loop to control number of comparisons per pass */
for (j = 0; j < tests -1; j++)
{
/* swap elements if out of order */
if (studentScores[i][j] > studentScores[i][j + 1]) {
hold = studentScores[i][j];
studentScores[i][j] = studentScores[i][j + 1];

studentScores[i][j + 1] = hold;
}
}
}

}

## Recommended

#### Calculate Friction Factor

Or use your account on DocShare.tips

Hide