fork(1) 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. struct Body a[5] = {
  18. {1, 65, 169},
  19. {2, 73, 170},
  20. {3, 59, 161},
  21. {4, 79, 175},
  22. {5, 55, 168}
  23. };
  24.  
  25. int i, j;
  26.  
  27. for (i = 0; i < 4; i++) {
  28. for (j = i + 1; j < 5; j++) {
  29. if (a[i].height < a[j].height) {
  30. swap(&a[i], &a[j]);
  31. }
  32. }
  33. }
  34. for (i = 0; i < 5; i++) {
  35. printf("ID:%d 体重:%d 身長:%d\n",
  36. a[i].id, a[i].weight, a[i].height);
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
ID:4 体重:79 身長:175
ID:2 体重:73 身長:170
ID:1 体重:65 身長:169
ID:5 体重:55 身長:168
ID:3 体重:59 身長:161