Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
calculate meian

calculate meian

Ratings: (0)|Views: 20|Likes:
Published by ahmad
for c++ calculate median
for c++ calculate median

More info:

Published by: ahmad on Mar 04, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

06/16/2009

pdf

text

original

 
#include <stdio.h>#define STUDENTS 100#define EXAMS 4int 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 *******************************************************/printf("\n\nLowest grade: %d\nHighest grade: %d\n",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;
 
}/******************************************************************************** Find the minimum grade ******************************************************************************/int minimum( const int scores[][EXAMS], int pupils, int tests ){int i; /* student counter */int j; /* exam counter */int lowGrade = 100; /* initialize to highest possible grade *//* 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] < lowGrade) {lowGrade = scores[i][j];}}} /*return lowGrade;}/****************************************************************** Find the maximum grade ****************************************************************/int maximum( const int scores[][EXAMS], int pupils, int tests){int i;int j;int highGrade = 0; /*initialize to lowest possible grade *//* 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 ) {highGrade = scores[i][j];}}}return 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];

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->