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++) printf("%d, ",array[j]);
  11. printf("\n");
  12. }
  13.  
  14. int main(void) {
  15. int array[10] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
  16. int size = 10;
  17. for (int pass = 0; pass < size - 1; pass++) {
  18. for (int j = 0; j < size - 1; j++) {
  19. if (array[j] > array[j + 1]) swap(&array[j], &array[j + 1]);
  20. imprime(array, size);
  21. }
  22. printf("--- Nova iteração ---\n");
  23. }
  24. }
  25.  
  26. //http://pt.stackoverflow.com/q/178136/101
Success #stdin #stdout 0s 4440KB
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 ---