Cho bản ghi gồm: Họ và tên và điểm của từng học sinh trong lớp. Hãy xuất ra tên và điểm của từng học sinh theo thứ tự điểm cao xuống thấp

1 câu trả lời

Program Sap_xep;
Uses crt;
Const Max=60;
Type hocsinh = record
        Hoten:string[30];
        Diem:real;
               End;
Var
        Lop: array[1..Max] of hocsinh;
        N,i,j:byte;
        Tam:real;
Begin
        Clrscr;
        Write('Nhap so hoc sinh : '); readln(n);
        For i:=1 to n do
        Begin
                Writeln('Nhap so lieu ve hoc sinh thu ',i,': ');
                Write('Ho va ten: '); readln(Lop[i].Hoten);
                Write('Diem: '); readln(Lop[i].Diem);
        End;
        For i:=1 to n-1 do
                For j:=i+1 to n do
                If Lop[i].Diem>Lop[j].diem then
                Begin
                        Tam:=Lop[i].Diem;
                        Lop[i].Diem:=Lop[j].Diem;
                        Lop[j].diem:=Tam;
                End;
        Clrscr;
        Write('Danh sach hoc sinh trong lop: ');
        For i:=1 to N do
        Begin
                Write('Hoc sinh thu ',i);
                Writeln;
                Write('Ho va ten: ',Lop[i].Hoten);
                Writeln;
                Write('Diem: ',Lop[i].Diem:0:2);
                Writeln;
        End;

        Write('Sau khi sap xep: ');
        Writeln;
        For i:=1 to n do
        Begin
                Write('Ho ten: ',Lop[i].hoten);
                Writeln;
                Write('Diem: ',Lop[i].diem:0:2);
                Writeln;
        End;
        Readln;
End.

Câu hỏi trong lớp Xem thêm