fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <inttypes.h>
  4.  
  5. #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } while ( 0 )
  6.  
  7. int main(void)
  8. {
  9. size_t array_ptr;
  10.  
  11. char n; // true-false
  12. int16_t array[] =
  13. {
  14. 50, -62, 10, 617, -174, 22, 274, 22, 7, 28, -2888, 16, 6, // сюда можно копипастить хрень
  15. };
  16. size_t array_end = sizeof(array)/sizeof(array[0]);
  17. do
  18. {
  19. n=0; // FALSE
  20. array_ptr = 0; // SET PTR TO THE BEGIN
  21.  
  22. while (array_ptr != (array_end-1) ) // COMPARE POINTERS
  23. {
  24. if ( array[array_ptr] > array[array_ptr+1] ) // COMPARE VALUES
  25. {
  26. SWAP( array[array_ptr], array[array_ptr+1] ); // SWAP VALUES
  27. n=1; // TRUE
  28. }
  29. array_ptr++;
  30. }
  31.  
  32. }
  33. while (n);
  34.  
  35. array_ptr=0;
  36. while (array_ptr != array_end)
  37. {
  38. printf( "%" PRId16 ", ", array[array_ptr] );
  39. array_ptr++;
  40. }
  41.  
  42. printf("\n");
  43. return 0;
  44. }
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
-2888, -174, -62, 6, 7, 10, 16, 22, 22, 28, 50, 274, 617,