fork download
  1. typedef struct {
  2. int id;
  3. int weight;
  4. int height;
  5. } Body;
  6.  
  7.  
  8. void swap(Body *a, Body *b) {
  9. Body w = *a;
  10. *a = *b;
  11. *b = w;
  12. }
  13.  
  14. int main() {
  15.  
  16. Body a[] = {
  17. {1, 65, 169},
  18. {2, 73, 170},
  19. {3, 59, 161},
  20. {4, 79, 175},
  21. {5, 55, 168},
  22. };
  23.  
  24.  
  25. printf("ID\tWeight\tHeight\n");
  26.  
  27.  
  28. for (int i = 0; i <5; i++) {
  29. for (int j = 0; j < 4; j++) {
  30. if (a[i].height < a[j+1].height) {
  31. swap(&a[i], &a[j+1]);
  32. }
  33. if (a[j].height < a[j + 1].height) {
  34. swap(&a[j], &a[j + 1]);
  35. }
  36. } printf("%d\t%d\t%d\n", a[i].id, a[i].weight, a[i].height);
  37.  
  38. }
  39.  
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
ID	Weight	Height
4	79	175
2	73	170
1	65	169
5	55	168
3	59	161