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