Skip to content

Instantly share code, notes, and snippets.

@iceandguard
Created January 2, 2011 16:07
Show Gist options
  • Save iceandguard/762609 to your computer and use it in GitHub Desktop.
Save iceandguard/762609 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define MAX_STDT 5
#define MAX_OBJT 5
/* 3(KOR ENG MATH) -> 5(KOR ENG MATH TOT AVG) */
int main() {
int i, j, tot, r, score[MAX_STDT][MAX_OBJT], *tmp = 0;
float avg;
printf("Enter the score...\n");
for(i=0; i<MAX_STDT; i++) {
printf("%d: ", i+1);
scanf("%d %d %d", &score[i][0], &score[i][1], &score[i][2]);
/* do not use scanf_s. it's an implementation dependent stuff. */
}
printf("NO KOR ENG MATH TOT AVG RANK\n");
for (i = 0; i < MAX_STDT; ++i) {
tot = score[i][0] + score[i][1] + score[i][2];
score[i][3] = tot;
}
for(i = 0; i < MAX_STDT; ++i) {
r = 1;
for(j = 0; j < MAX_STDT; ++j) {
if (score[i][3] < score[j][3])
r++;
}
score[i][4] = r;
}
for (i = 0; i < MAX_STDT; ++i) {
for (j = 0; j < MAX_STDT; ++j) { /* remove a dupilcated declaration. */
if (score[j][4] == i+1 && tmp != &score[j][4]) {
tmp = &score[j][4];
tot = score[j][3];
avg = tot/3.0;
printf("%d: %3d %3d %3d %3d %3.2f %d\n", j+1, score[j][0],
score[j][1], score[j][2], score[j][3], avg, score[j][4]);
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment