Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct hocsinh
- {
- char hoten[31];
- char mssv[10];
- float dt, dv, dtb;
- };
- void nhaptunghocsinh(int i, hocsinh &hs)
- {
- printf("Hoc sinh thu %d: \n", i);
- printf("\n\tTen: "); gets_s(hs.hoten);
- printf("\n\tMSSV: "); gets_s(hs.mssv);
- printf("\n\tDiem toan: "); scanf_s("%f", &hs.dt); scanf("%*c");
- printf("\n\tDiem van: "); scanf_s("%f", &hs.dv); scanf("%*c");
- }
- void nhap(int n, hocsinh hs[])
- {
- for (int i = 0; i < n; i++)
- {
- nhaptunghocsinh(i + 1, hs[i]);
- }
- }
- void tinhtrungbinh(int n, hocsinh hs[])
- {
- for (int i = 0; i < n; i++)
- hs[i].dtb = (hs[i].dt + hs[i].dv) / 2;
- }
- int tbmax(int n, hocsinh hs[])
- {
- int *x = (int *)malloc(n * sizeof(int));
- if (x == NULL) return -1;
- int t;
- for (int i = 0; i < n; i++) x[i] = i;
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- if (hs[x[i]].dtb < hs[x[j]].dtb)
- {
- t = x[i];
- x[i] = x[j];
- x[j] = t;
- }
- }
- }
- t = x[0];
- free(x);
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement