Mình chạy hàm sắp xếp tên theo điểm trung bình mà sao khi xuất ra nó không sắp xếp vậy ạ
#include<stdio.h>
#include<string>
#include<stdlib.h>
const int MAX = 200;
struct SINHVIEN
{
char Mssv[20] ;
char Hoten[20] ;
float DTB ;
};
typedef struct SINHVIEN SinhVien ;
struct LOPHOC
{
SinhVien dssv[MAX];
char TenLop[20];
int siso;
};
typedef struct LOPHOC LOP ;
void Nhap_Lop(LOP &Lop)
{
SinhVien dssv[MAX];
printf(" Nhap Ten Lop :");
gets(Lop.TenLop);
printf(" Nhap Si So lop :");
scanf("%d",&Lop.siso);
for(int i=0;i<Lop.siso;i++)
{
printf("\n Nhap Sinh Vien thu :%d",i+1);
fflush(stdin);
printf("\n Nhap Ten Sinh Vien :");
gets(Lop.dssv[i].Hoten);
fflush(stdin);
printf(" Ma So Sinh Vien :");
gets(Lop.dssv[i].Mssv);
printf(" Nhap Diem Trung Binh :");
scanf("%f",&Lop.dssv[i].DTB);
}
}
void Xuat_Lop(LOP Lop)
{
//SinhVien dssv[MAX];
printf(" Ten Lop La :");
puts(Lop.TenLop);
printf(" Si So Lop :%d",Lop.siso);
for(int i=0;i<Lop.siso;i++)
{
printf("\n Sinh Vien thu :%d",i+1);
fflush(stdin);
printf("\n Ten Sinh Vien :");
puts(Lop.dssv[i].Hoten);
printf("\n Ma So Sinh Vien :");
puts(Lop.dssv[i].Mssv);
printf("\n Diem Trung Binh :%.2f",Lop.dssv[i].DTB);
}
}
void Sap_xep_ds(LOP Lop)
{
//SinhVien dssv[MAX];
for(int i=0;i<(Lop.siso)-1;i++)
for(int j=i+1;j<Lop.siso;j++)
{
if(Lop.dssv[i].DTB<Lop.dssv[j].DTB)
{
float t;
t=Lop.dssv[i].DTB;
Lop.dssv[i].DTB=Lop.dssv[j].DTB;
Lop.dssv[j].DTB=t;
}
}
}
int main()
{
//SinhVien dssv[MAX];
LOP Lop;
Nhap_Lop(Lop);
//printf(" Danh Sach Vua Nhap La :\n");
//Xuat_Lop(Lop);
Sap_xep_ds(Lop);
printf("\n Danh sah vua sap xep la :\n");
Xuat_Lop(Lop);
return 0;
}



83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?