#include <stdio.h>
 
struct student {
    int id;     /* 学籍番号 */
    int eng;    /* 英語の成績 */
    int math;   /* 数学の成績 */
    int sci;    /* 理科の成績 */
};
 
#define N 3
 
int main(){
    int i, j;
    struct student s[N] = {
        {17001,  60, 100,  20},  /* 合計: 180 */
        {17002,  90,  40,  80},  /* 合計: 210 */
        {17003,  20,  30,  50}}; /* 合計: 100 */
    struct student tmp;
    
     /* ソート（3教科の合計点で昇順） */
    for (i=1; i<N; i++) {
        for (j=0; j<N-i; j++){
            /* j番目とj+1番目の生徒の「3教科の合計点」を比較 */
            if( (s[j].eng + s[j].math + s[j].sci) > (s[j+1].eng + s[j+1].math + s[j+1].sci) ){
                tmp = s[j];
                s[j] = s[j + 1];
                s[j+1] = tmp;
            }
        }
    }
 
  /* 成績のプリント */
    for(i=0; i<N; i++) {
        /* 各生徒の合計点を計算 */
        int total = s[i].eng + s[i].math + s[i].sci;
    	printf("学籍番号:%-7d 英語:%-5d 数学:%-5d 理科:%-5d 合計:%-5d\n",
        s[i].id, s[i].eng, s[i].math, s[i].sci, total);
    }
 
    return 0;
}
