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