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 temp=*x;
  13. *x=*y;
  14. *y=temp;
  15. }
  16.  
  17. int main(){
  18. struct Body a[]={
  19. {1,65,169},
  20. {2,73,170},
  21. {3,59,161},
  22. {4,79,175},
  23. {5,55,168}
  24. };
  25. int n=sizeof(a)/sizeof(a[0]);
  26.  
  27. for(int i=0;i<n-1;i++){
  28. for(int j=0;j<n-1-i;j++){
  29. if(a[j].height<a[j+1].height){
  30. swap(&a[j],&a[j+1]);
  31. }
  32. }
  33. }
  34.  
  35. for(int i=0;i<n;i++){
  36. printf("%d, %d, %d\n",a[i].id,a[i].weight,a[i].height);
  37. }
  38.  
  39. return 0;
  40. }
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