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. for (int i = 0; i < 2; i++) {
  30. temp = data[i];
  31. data[i] = data[4 - i];
  32. data[4 - i] = temp;
  33. }
  34. }
  35.  
  36. void display(Body data[]) {
  37. for (int i = 0; i < 5; i++) {
  38. printf("ID: %d, Weight: %d, Height: %d\n", data[i].id, data[i].weight, data[i].height);
  39. }
  40. }
Success #stdin #stdout 0s 5252KB
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