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