Advertisement
huutho_96

cautruc

Jan 11th, 2015
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct hocsinh
  4. {
  5. char hoten[31];
  6. char mssv[10];
  7. float dt, dv, dtb;
  8. };
  9. void nhaptunghocsinh(int i, hocsinh &hs)
  10. {
  11. printf("Hoc sinh thu %d: \n", i);
  12. printf("\n\tTen: "); gets_s(hs.hoten);
  13. printf("\n\tMSSV: "); gets_s(hs.mssv);
  14. printf("\n\tDiem toan: "); scanf_s("%f", &hs.dt); scanf("%*c");
  15. printf("\n\tDiem van: "); scanf_s("%f", &hs.dv); scanf("%*c");
  16. }
  17. void nhap(int n, hocsinh hs[])
  18. {
  19. for (int i = 0; i < n; i++)
  20. {
  21. nhaptunghocsinh(i + 1, hs[i]);
  22. }
  23. }
  24. void tinhtrungbinh(int n, hocsinh hs[])
  25. {
  26. for (int i = 0; i < n; i++)
  27. hs[i].dtb = (hs[i].dt + hs[i].dv) / 2;
  28. }
  29. int tbmax(int n, hocsinh hs[])
  30. {
  31. int *x = (int *)malloc(n * sizeof(int));
  32. if (x == NULL) return -1;
  33. int t;
  34. for (int i = 0; i < n; i++) x[i] = i;
  35. for (int i = 0; i < n; i++)
  36. {
  37. for (int j = i + 1; j < n; j++)
  38. {
  39. if (hs[x[i]].dtb < hs[x[j]].dtb)
  40. {
  41. t = x[i];
  42. x[i] = x[j];
  43. x[j] = t;
  44. }
  45. }
  46. }
  47. t = x[0];
  48. free(x);
  49. return t;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement