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