fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int numbers[7] = {2, 7, 6, 3, 1, 5, 4};
  5.  
  6. int swapCounter = 1;
  7. int swaps = 0;
  8. int temp = 0;
  9.  
  10. while (swapCounter != 0){
  11. swaps = 0;
  12. for (int i = 0; i < 7 - 1; i = i + 1) {
  13. if (numbers[i] > numbers[i+1]) {
  14. temp = numbers[i];
  15. numbers[i] = numbers[i+1];
  16. numbers[i+1] = temp;
  17. swaps = swaps + 1;
  18. }
  19. }
  20. swapCounter = swaps;
  21. }
  22.  
  23. printf("%d\n", numbers[0]);
  24. printf("%d\n", numbers[1]);
  25. printf("%d\n", numbers[2]);
  26. printf("%d\n", numbers[3]);
  27. printf("%d\n", numbers[4]);
  28. printf("%d\n", numbers[5]);
  29. printf("%d\n", numbers[6]);
  30. }
Success #stdin #stdout 0s 9416KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6
7