Skip to content

Instantly share code, notes, and snippets.

@mgarciaisaia
Created December 14, 2012 14:50
Show Gist options
  • Save mgarciaisaia/4285964 to your computer and use it in GitHub Desktop.
Save mgarciaisaia/4285964 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
void main(void) {
int numeros[15];
int i = 0;
numeros[i++] = 0;
numeros[i++] = 1;
numeros[i++] = 2;
numeros[i++] = 0;
numeros[i++] = 0;
numeros[i++] = 1;
numeros[i++] = 2;
numeros[i++] = 0;
numeros[i++] = 0;
numeros[i++] = 0;
numeros[i++] = 1;
numeros[i++] = 2;
numeros[i++] = 0;
numeros[i++] = 0;
int j = 0;
int aux;
int k;
for(k=0; k<1; k++) {
printf("Iteracion %d\n", k + 1);
for(j=0; j<i-2; j++) {
if(numeros[j]==numeros[j+1]) {
printf("En numeros[%d]=%d cambio numeros[%d]=%d por numeros[%d]=%d\n", j, numeros[j], j+1, numeros[j+1], j+2, numeros[j+2]);
aux = numeros[j + 1];
numeros[j+1] = numeros[j+2];
numeros[j+2] = aux;
}
}
for(j=0; j<i; j++) {
printf("%d, ", numeros[j]);
}
printf("\n\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment