Skip to content

Instantly share code, notes, and snippets.

@bongtrop
Last active December 22, 2015 05:19
Show Gist options
  • Save bongtrop/6423465 to your computer and use it in GitHub Desktop.
Save bongtrop/6423465 to your computer and use it in GitHub Desktop.
การบ้านพะเยา
#include <stdio.h>
#include <stdlib.h>
int cmp_array(const void *a, const void *b) {
int *aa=(int *)a;
int *bb=(int *)b;
return aa[0] - bb[0];
}
int main() {
int i, sum=0;
int score[10][2];
char name[10][100];
for (i=0;i<10;i++) {
printf ("Name Student %d :: ", i+1);
scanf ("%s", name[i]);
printf ("Score Student %d :: ", i+1);
scanf ("%d", &score[i][0]);
score[i][1]=i;
sum+=score[i][0];
}
qsort(score, 10, sizeof(int)*2, cmp_array);
printf ("\n%s have score %d is Maximum\n", name[score[9][1]], score[9][0]);
printf ("%s have score %d is Minimum\n\n", name[score[0][1]], score[0][0]);
printf ("Sum of all score is %d\n", sum);
printf ("Average of all score is %.2f\n", (float)sum/10);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment