fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. typedef struct {
  5. int id;
  6. int weight;
  7. int height;
  8. } Body;
  9.  
  10.  
  11. void swap(Body* a, Body* b) {
  12. Body temp = *a;
  13. *a = *b;
  14. *b = temp;
  15. }
  16.  
  17.  
  18. void s(Body a[], int n) {
  19. for (int i = 0; i < n - 1; i++) {
  20. for (int j = i + 1; j < n; j++) {
  21. if (a[i].height < a[j].height) {
  22. swap(&a[i], &a[j]);
  23. }
  24. }
  25. }
  26. }
  27.  
  28.  
  29. void display(Body a[], int n) {
  30. for (int i = 0; i < n; i++) {
  31. printf("%d %d %d\n", a[i].id, a[i].weight, a[i].height);
  32. }
  33. }
  34.  
  35. int main() {
  36.  
  37. Body a[] = {
  38. {1, 65, 169},
  39. {2, 73, 170},
  40. {3, 59, 161},
  41. {4, 79, 175},
  42. {5, 55, 168}
  43. };
  44.  
  45. int n = sizeof(a) / sizeof(a[0]);
  46. s(a, n);
  47. display(a, n);
  48.  
  49. return 0;
  50. }
  51.  
  52.  
  53.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
4 79 175
2 73 170
1 65 169
5 55 168
3 59 161