1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include<stdio.h>
#include<stdlib.h>
#define STUDENTS 5
#define QUIZZES 7
main() {
int quizScores[STUDENTS][QUIZZES] = {
{ 90, 67, 45, 56, 77, 88, 45 },
{ 65, 80, 87, 60, 55, 100, 78 },
{ 90, 89, 88, 66, 100, 90, 99 },
{ 54, 67, 80, 75, 45, 45, 87 },
{ 78, 66, 48, 99, 61, 82, 95 }
};
int studentTotal = 0, quizTotal = 0, row, col, lowestQuiz[QUIZZES], highestQuiz[QUIZZES];
double studentAverage[STUDENTS], quizAverage[QUIZZES], highestAverage;
int i = 0;
for (row = 0; row < STUDENTS; row++) {
studentTotal = 0;
for (col = 0; col < QUIZZES; col++) {
studentTotal += quizScores[row][col];
}
studentAverage[row] = (double)studentTotal / QUIZZES;
printf("Student %i had average %.2lf\n", row + 1, studentAverage[row]);
if (row == 4) {
printf("\n");
}
}
highestAverage = studentAverage[0];
for (i = 1; i < STUDENTS; i++) {
if (highestAverage < studentAverage[i]) {
highestAverage = studentAverage[i];
}
}
printf("Student %d has the highest average with a score of %.2lf\n\n", i, highestAverage);
for (col = 0; col < QUIZZES; col++) {
quizTotal = 0;
for (row = 0; row < STUDENTS; row++) {
quizTotal += quizScores[row][col];
}
quizAverage[col] = (double)quizTotal / STUDENTS;
printf("Quiz %i had average %.2lf\n", col + 1, quizAverage[col]);
if (col == 6) {
printf("\n");
}
}
printf("Quiz Grades Range\n");
for (i = 0; i < QUIZZES; i++) {
for (col = i; col < QUIZZES; col++) {
lowestQuiz[i] = quizScores;
for (row = 0; row < STUDENTS; row++) {
if (lowestQuiz[i] > quizScores[row][col]) {
lowestQuiz[i] = quizScores[row][col];
}
}
i++;
}
}
for (i = 0; i < QUIZZES; i++) {
for (col = i; col < QUIZZES; col++) {
for (row = 0; row < STUDENTS; row++) {
if (highestQuiz[i] < quizScores[row][col]) {
highestQuiz[i] = quizScores[row][col];
}
}
i++;
}
}
printf("Quiz 1: %d - %d\n", lowestQuiz[i], highestQuiz[col]);
printf("Quiz 2: %d - %d\n", lowestQuiz[i], highestQuiz[col]);
printf("Quiz 3: %d - %d\n", lowestQuiz[i], highestQuiz[col]);
printf("Quiz 4: %d - %d\n", lowestQuiz[i], highestQuiz[col]);
printf("Quiz 6: %d - %d\n", lowestQuiz[i], highestQuiz[col]);
printf("Quiz 7: %d - %d\n", lowestQuiz[i], highestQuiz[col]);
system("pause");
}
|