#include<stdio.h>
struct sv
{
char hoten[30];
char MSSV[30];
float toan, li, hoa, dtb;
};
void nhapSV(sv& x);
void xuatSV(sv x);
void nhap1lop(sv A[], int& n);
void xuat1lop(sv A[], int n);
void tinhTB(sv A[], int n);
sv timSVDTBMax(sv A[], int n);
void hoandoi(sv& x, sv& y);
void sapxep(sv A[], int n);
void main()
{
sv A[40];
int n;
nhap1lop(A, n);
tinhTB(A, n);
sapxep(A, n);
xuat1lop(A, n);
sv x = timSVDTBMax(A, n);
xuatSV(x);
}
void nhapSV(sv& x)
{
printf("nhap ho ten ");
fflush(stdin);
gets_s(x.hoten );
printf("nhap MSSV ");
fflush(stdin);
gets_s(x.MSSV);
printf("diem 3 mon");
float t, l, h;
scanf_s("%f%f%f", &t, &l, &h);
x.toan = t;
x.li = l;
x.hoa = h;
}
void xuatSV(sv x)
{
printf("%s %s %f %f %f %f", x.hoten, x.MSSV, x.toan, x.li, x.hoa,x.dtb);
}
void nhap1lop(sv A[], int& n)
{
printf("nhap so SV n=");
scanf_s("%d", &n);
for (int i = 0; i < n; i++)
{
nhapSV(A[i]);
}
}
void xuat1lop(sv A[], int n)
{
for (int i = 0; i < n; i++)
{
xuatSV(A[i]);
}
}
void tinhTB(sv A[], int n)
{
for (int i = 0; i < n; i++)
A[i].dtb = (A[i].toan + A[i].li + A[i].hoa) / 3;
}
sv timSVDTBMax(sv A[], int n) {
float max = A[0].dtb;
int vitri = 0;
for (int i = 1; i < n; i++)
{
if (max < A[i].dtb)
{
max = A[i].dtb;
vitri = i;
}
}
return A[vitri];
}
void sapxep(sv A[], int n)
{
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
{
if (A[i].dtb > A[j].dtb)
hoandoi(A[i], A[j]);
}
}
void hoandoi(sv& x, sv& y)
{
sv k = x;
x = y;
y = k;
}
khi nhập xong số sinhvien thi màn hình hiện ra hotenMSSV khi nhập thì cả họ tên và mssv đều giống nhau (VS 2019)
còn MS C++ 6.0 thì vẫn bình thường ạ
mọi người chỉ dúp em với ạ