Code:
struct stud{
char name[30];
int grade[4];
float avg;
}
Then in the program i do this:
Code:
struct stud students[];
..
..
Then I need a function which will sort the grades for each student from lowest to highest..
N is the number of students
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;
}
}
will this work ??
any help?
all I want to know is how to sort the 4 grades within the structure for each student.