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 *b, Body *c);
  10.  
  11. int main(void) {
  12. Body data[] = {
  13. { 1, 65, 169 },
  14. { 2, 73, 170 },
  15. { 3, 59, 161 },
  16. { 4, 79, 175 },
  17. { 5, 55, 168 }};
  18. for (int i=0;i<4;i++){
  19. for(int j=i+1;j<5;j++){
  20. if(data[i].height<data[j].height){
  21. swap(&data[i],&data[j]);
  22. }
  23. }
  24. }
  25. //for文を使って、表示する
  26. for(int d=0;d<5;d++){
  27. printf("%d,",data[d].id);
  28. printf("%d,",data[d].weight);
  29. printf("%d\n",data[d].height);
  30. }
  31. return 0;
  32. }
  33.  
  34. void swap(Body *b, Body *c){
  35. Body e;
  36. e = *b;
  37. *b = *c;
  38. *c = e;
  39. }
  40.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
4,79,175
2,73,170
1,65,169
5,55,168
3,59,161