Problem with vector ordering [closed]

0

Good afternoon, I'm having a problem with a vector ordering exercise, I have already reviewed the code, it compiles, but I'm not finding the error for the order not to stay increasing, varying in certain passages. Here is the code:

#include <stdio.h> //Declaracao de bibliteca para entradas e saidas de valores

int main (void) //Declaracao do programa principal
{
    int i, j, troca, vetorA[10];
    for (i = 0; i < 10 ; i++)
    {
        printf("Digite o valor do elemento:");
        scanf("%d", &vetorA[i]);
    }
    for(i=0; j<10; i++)
    {
        for (j=i+1; j<10; j++)
        {   
            if(vetorA[i]>vetorA[j])
            {
                troca=vetorA[i];
                vetorA[i] = vetorA[j];
                vetorA[j] = troca;
            }
        }
    }
    printf("\nvetor ordenado \n");
    for(i=0; i<10; i++)
    {
        printf("%d - ", vetorA[i]);
    }
    system("pause");
    return 0;
}
    
asked by anonymous 12.04.2015 / 20:17

2 answers

2

instead of

for(i=0; j<10; i++)

Pqrece me what you wanted to say

for(i=0; i<10; i++)
    
12.04.2015 / 20:35
2

I believe it was a typo only:

#include <stdio.h>

int main (void) {
    int i, j, troca, vetorA[10];

    for (i = 0; i < 10; i++) {
        printf("Digite o valor do elemento:");
        scanf("%d", &vetorA[i]);
    }

    for(i = 0; i < 10; i++) { // <=========== Aqui tinha um j < 10 que obviamente causa confusão
        for (j = i + 1; j < 10; j++) {  
            if(vetorA[i] > vetorA[j])   {
                troca = vetorA[i];
                vetorA[i] = vetorA[j];
                vetorA[j] = troca;
             }
        }
    }
    printf("\nvetor ordenado\n");

    for(i = 0; i < 10; i++) {
        printf("%d - ", vetorA[i]);
    }
    return 0;
}

See running on ideone .

    
12.04.2015 / 20:35