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