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 as many warnings as possible from your compiler and always correct the displayed warnings.
After correcting the warnings (and format to my taste) the code was 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;
}
Now we need to implement the Bubble Sort correctly and make the final impression with a loop, as you did in the initial impression.