My compiler gives warnings in several lines:
pt91088.c:5:34: warning: data argument not used by format string
[-Wformat-extra-args]
printf("Informe valor:", vetor[i]);
~~~~~~~~~~~~~~~~ ^
pt91088.c:9:22: warning: data argument not used by format string
[-Wformat-extra-args]
printf("\t", vetor[i]);
~~~~ ^
pt91088.c:20:16: warning: using the result of an assignment as a condition
without parentheses [-Wparentheses]
} while (i = 1);
~~^~~
pt91088.c:20:16: note: place parentheses around the assignment to silence this
warning
} while (i = 1);
^
( )
pt91088.c:20:16: note: use '==' to turn this assignment into an equality
comparison
} while (i = 1);
^
==
3 warnings generated.
Tip: Turn on the maximum warnings from your compiler and always correct the warnings that appear.
After correcting warnings (and formatting to my liking) the code looks like this:
#include <stdio.h>
int main(void) {
int vetor[10], i, a; // variavel t desnecessaria e removida
for (i = 0; i < 10; i++) {
printf("Informe valor:"); // removido valor desnecessario
scanf("%d", &vetor[i]);
}
for (i = 0; i < 10; i++) {
printf("\t%d", vetor[i]); // adicionado %d para imprimir valor
}
// ciclo do removido
for (i = 0; i < 10; i++) {
if (vetor[i] > vetor[i + 1]) {
a = vetor[i];
vetor[i] = vetor[i + 1];
vetor[i + 1] = a;
}
}
printf("O vetor em ordem crescente e: %d\n", vetor[i]); // acrescentado \n
return 0;
}
Bubble Sort is now correctly implemented and the final print with a loop as you did in the initial print.