fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct{
  4. int ID;
  5. int weight;
  6. int height;
  7. }Body;
  8.  
  9. void swap(Body *x, Body *y){
  10. Body c = *x;
  11. *x = *y;
  12. *y = c;
  13. }
  14.  
  15. int main(void) {
  16. Body a[5] = {
  17. {1, 65, 169},
  18. {2, 73, 170},
  19. {3, 59, 161},
  20. {4, 79, 175},
  21. {5, 55, 168}
  22. };
  23.  
  24. //身長の降順に並び替えると
  25. int i=0;
  26. int j=0;
  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.  
  35. for (int i = 0; i < 5; i++) {
  36. printf("%d, %d, %d\n", a[i].ID, a[i].weight, a[i].height);
  37. }
  38. return 0;
  39. }
  40.  
  41.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161