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