Faça um programa que preencha um vetor com 8 números inteiros , ja os armazene de forma crescente

1 Resposta

  • Gustastrada

    #include

    #include

    #include

    #include

    int main()

    {

       setlocale(LC_ALL,"PORTUGUESE");

       srand(time(NULL));

       //CRIAR VARS

       int i, j, aux, vet[8];

       //INICIALIZAR VARS

       for(i=0; i<8; i++)

           vet[i] = 0;

       aux = 0;

       //PREENCHER E EXIBIR VETOR

       printf(" ");

       printf(" || PREENCHIMENTO DO VETOR ||");

       printf(" ");

       for(i=0; i<8; i++)

       {

           vet[i] = rand() % 100;

           printf(" VETOR POSIÇÃO [%2d]: %2d ",i+1,vet[i]);

       }

       //ORDENAR VETOR

       for(i=0; i<8; i++)

       {

           for(j=0; j<7; j++)

           {

               if(vet[i] < vet[j])

               {

                   aux = vet[j];

                   vet[j] = vet[i];

                   vet[i] = aux;

               }

           }

       }

       //EXIBIR VETOR ORDENADO

       printf(" ");

       printf(" || VETOR ORDENADO ||");

       printf(" ");

       for(i=0; i<8; i++)

           printf(" VETOR POSIÇÃO [%2d]: %2d ",i+1,vet[i]);

       return 0;

    }

Clique aqui para adicionar a sua resposta.