Then in the program i do this:Code:struct stud{ char name[30]; int grade[4]; float avg; }
Then I need a function which will sort the grades for each student from lowest to highest..Code:struct stud students[]; .. ..
N is the number of students
will this work ??Code:void sort(stuct student[], int n){ int i, j, lowest, highest, temp; for(i=0;i<n;i++) for(j=0;j<4;j++){ lowest=student[i].grade[j]; highest=student[i].grade[j+1]; if(lowest>highest){ temp=student[i].grade[j]; student[i].grade[j]=student[i].grade[j+1]; student[i].grade[j+1]=temp; } }
any help?
all I want to know is how to sort the 4 grades within the structure for each student.



LinkBack URL
About LinkBacks


