3
At the end of my program the result is giving random numbers, which occurs?
main(){
int i;
int a[10];
int x;
int aux;
for (i=0; i<10; i++){
printf ("Entre com os numeros %i: ", i);
scanf ("%i", & a[10]);
}
for(i = 0; i < 10; i++){
for (x=0; x<10; x++)
if (a[i]>a[x+1]){
aux = a[i];
a[i] = a[i+1];
a[i+1] = aux;
}
}
printf ("Lista dos elementos em ordem a seguir:\n ");
for (i = 0 ; i < 10; i++)
printf ("%i\n", a[i]);
}
I believe that the innermost link should start from i+1 and not from 0. Shouldn’t the exchange be between a[i] and a[x] in your program at[x+1]? I believe you have mixed two methods of ordination.
– anonimo
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero