Use vector in external functions a main

0

I learned to use functions a few days ago and now I wanted to use a vector in them. My teacher taught me, but my code just does not work. One of the numbers ends up being repeated. Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <locale.h>


void crescente(int vetor[],int n);//protótipo função
void decrescente(int vetor[],int n);//protótipo função

int main()
{

    setlocale(NULL,"");
    int vet[10],i,cod=3;


    printf("Digite dez números inteiros (aperte a tecla ENTER ao final de cada número)!\n");
    for(i=0;i<=9;i++)
        scanf("%d%*c",&vet[i]);

    system("cls");

   while(cod!=0)
   {


   printf("Escolha um código :\n1-Organizar em ordem crescente.\n2-Organizar em ordem decrescente.\n0-Finalizar o programa.\n\n");
   cod=getch()-48;

      if(cod==0)
           break;

      else if(cod==1)
           crescente(&vet,10);

      else if(cod==2)
           decrescente(vet,10);




   }
    return 0;
}


void crescente(int vetor[],int n)
{

int aux=0,control,i;

  do{
         control=0;

        for(i=0;i<=n-1;i++)
        {
            if(vetor[i]>vetor[i+1])
            {
                aux=vetor[i];
                vetor[i]=vetor[i+1];
                vetor[i+1]=aux;

                control=1;//controle do bubble sort que vi na internet,melhor q um FOR; kkkkkkk
            }
        }



    }while(control!=0);

    for(i=0;i<=n-1;i++)
        {
            printf("%d. ",*vetor[i]);

        }
     printf("\n\n\n");
}


void decrescente(int vetor[],int n)
{

int aux,control,i;

  do{
        control=0;

        for(i=0;i<=n-1;i++)
        {
            if(vetor[i]<vetor[i+1])
            {
                aux=vetor[i];
                vetor[i]=vetor[i+1];
                vetor[i+1]=aux;

                control=1;//controle do bubble sort que vi na internet,melhor q um FOR; kkkkkkk
            }
        }





    }while(control!=0);


    for(i=0;i<=n-1;i++)
        {
            printf("%d. ",vetor[i]);

        }
     printf("\n\n\n");
}
    
asked by anonymous 09.06.2016 / 21:10

1 answer

2

You have:

crescente(&vet,10);

E:

decrescente(vet,10);

Note that one is with & and the other is not. The correct one would be neither to have this. After that, in the crescente function you should have:

printf("%d. ", vetor[i]);

Instead of:

printf("%d. ",*vetor[i]);

That is, take that * . Note that the decrescente function is right at this point.

    
09.06.2016 / 21:18