fork download
  1. // define.c
  2. #include <stdio.h>
  3.  
  4. #define MAX_SCORE_SIZE 8
  5. #define SWAP(x, y) (y = x - y, x -= y, y += x)
  6.  
  7. int main(void)
  8. {
  9. int score[MAX_SCORE_SIZE]={40,60,10,0,50,70,20,30};
  10.  
  11. for (int i = 0; i < MAX_SCORE_SIZE - 1 ; ++i) {
  12. for (int j = 0; j < MAX_SCORE_SIZE - 1; ++j) {
  13. if (score[j] > score[j+1]) {
  14. SWAP(score[j], score[j+1]);
  15. }
  16. }
  17. }
  18.  
  19. for (int i = 0; i < MAX_SCORE_SIZE; ++i) {
  20. printf("score[%d]: %d\n", i, score[i]);
  21. }
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 5512KB
stdin
Standard input is empty
stdout
score[0]: 0
score[1]: 10
score[2]: 20
score[3]: 30
score[4]: 40
score[5]: 50
score[6]: 60
score[7]: 70