Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define Maxstudents 10
- struct student {
- char name;
- int kor;
- int eng;
- int math;
- int total;
- };
- int main()
- {
- struct student std[Maxstudents],temp;
- std[0].name = 'A';
- std[0].kor=43;
- std[0].eng=65;
- std[0].math=87;
- std[0].total=std[0].kor+std[0].eng+std[0].math;
- std[1].name = 'B';
- std[1].kor=38;
- std[1].eng=77;
- std[1].math=97;
- std[1].total=std[1].kor+std[1].eng+std[1].math;
- std[2].name = 'C';
- std[2].kor=88;
- std[2].eng=76;
- std[2].math=95;
- std[2].total=std[2].kor+std[2].eng+std[2].math;
- std[3].name = 'D';
- std[3].kor=92;
- std[3].eng=12;
- std[3].math=34;
- std[3].total=std[3].kor+std[3].eng+std[3].math;
- std[4].name = 'E';
- std[4].kor=98;
- std[4].eng=97;
- std[4].math=81;
- std[4].total=std[4].kor+std[4].eng+std[4].math;
- std[5].name = 'F';
- std[5].kor=56;
- std[5].eng=36;
- std[5].math=94;
- std[5].total=std[5].kor+std[5].eng+std[5].math;
- std[6].name = 'G';
- std[6].kor=23;
- std[6].eng=99;
- std[6].math=87;
- std[6].total=std[6].kor+std[6].eng+std[6].math;
- std[7].name = 'H';
- std[7].kor=73;
- std[7].eng=62;
- std[7].math=43;
- std[7].total=std[7].kor+std[7].eng+std[7].math;
- std[8].name = 'I';
- std[8].kor=67;
- std[8].eng=55;
- std[8].math=82;
- std[8].total=std[8].kor+std[8].eng+std[8].math;
- std[9].name = 'J';
- std[9].kor=99;
- std[9].eng=75;
- std[9].math=47;
- std[9].total=std[9].kor+std[9].eng+std[9].math;
- int i,j;
- for (i = 0;i < Maxstudents-1;i++){
- for(j = 1+i; j < Maxstudents;j++){
- if ( std[i].total < std[j].total){
- std[i] = temp;
- std[i] = std[j];
- std[j] = temp;
- }
- }
- }
- printf("After BubbleSorting\n");
- for(i=0;i<Maxstudents;i++){
- printf("%c\t", std[i].name);
- printf("%d\t", std[i].kor);
- printf("%d\t", std[i].eng);
- printf("%d\t", std[i].math);
- printf("%d\t", std[i].total);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement