fork download
  1. #include <stdio.h>
  2.  
  3. void swap(int *e1, int *e2) {
  4. int tmp = *e1;
  5. *e1 = *e2;
  6. *e2 = tmp;
  7. }
  8.  
  9. void imprime(int array[], int size) {
  10. for (int j = 0; j < size; j++) {
  11. printf("%d, ",array[j]);
  12. }
  13. printf("\n");
  14. }
  15.  
  16. int main(void) {
  17. int array[10] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
  18. int size = 10;
  19. for (int pass = 0; pass < size - 1; pass++) {
  20. for (int j = 0; j < size - 1; j++) {
  21. if (array[j] > array[j + 1]) {
  22. swap(&array[j], &array[j + 1]);
  23. }
  24. imprime(array, size);
  25. }
  26. printf("--- Nova iteração ---\n");
  27. }
  28. }
  29.  
  30.  
  31. //http://pt.stackoverflow.com/q/178136/101
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
2, 6, 4, 8, 10, 12, 89, 68, 45, 37, 
2, 4, 6, 8, 10, 12, 89, 68, 45, 37, 
2, 4, 6, 8, 10, 12, 89, 68, 45, 37, 
2, 4, 6, 8, 10, 12, 89, 68, 45, 37, 
2, 4, 6, 8, 10, 12, 89, 68, 45, 37, 
2, 4, 6, 8, 10, 12, 89, 68, 45, 37, 
2, 4, 6, 8, 10, 12, 68, 89, 45, 37, 
2, 4, 6, 8, 10, 12, 68, 45, 89, 37, 
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
2, 4, 6, 8, 10, 12, 68, 45, 37, 89, 
2, 4, 6, 8, 10, 12, 45, 68, 37, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 45, 37, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
2, 4, 6, 8, 10, 12, 37, 45, 68, 89, 
--- Nova iteração ---