Professional Documents
Culture Documents
Marks Stats
Marks Stats
int main() {
// array of marks
float marks[] = {78, 89, 90, 67, 88, 90, 76, 89, 91, 78};
float average = sum/numOfMarks; // calculate the mean by dividing the sum by the
number of marks
float median;
// int maxIndex = numOfMarks - 1; // calculate the maximum index of the marks array
// int middleIndex = maxIndex/2; // calculate the middle index of the sorted marks
// float median = marks[middleIndex]; // calculate the median by getting the middle
value of the sorted marks
int isCounted[10] = {0}; // array to keep track of the marks that have been
counted, 0 means not counted, 1 means counted
// loop through the marks to find the mode
for(int i = 0; i < 10; i++){
if (isCounted[i] == 1){ // if the mark has already been counted, skip it
continue;
}
int count = 1;
// loop through the rest of the marks to find the count of the current mark
for (int j = i + 1; j < 10; j++){
if (marks[j] == marks[i]){
count++;
isCounted[j] = 1;
}
}
// if the count of the current mark is greater than the maximum count, update
the maximum count and mode
if (count > maxCount){
maxCount = count;
mode = marks[i];
}
}