3
Something is missing in the program. It checks the order with a single number or a single time.
#include <stdio.h>
#include <stdlib.h>
/*4)escrever 10 números e ordenar em forma crescente e decrescente*/
int main()
{
int opc;
int numA=0, numB=0, numC=0, soma, aux=0, i;
int vet[10];
float media;
printf("escolha qual exercicio quer executar:\n1)Ex1\n2)Ex2\n3)Ex3\n4)Ex4\n");
scanf("%i", &opc);
fflush(stdin);
system("cls");
switch(opc)
{
case 4:
printf("digite 10 numeros aleatorios:\n");
/*inicio da fase de processamento*/
for(i=0; i<10; i++)
{
scanf("%i", &vet[i]);
}
for(i=0; i<10; i++)/*crescente*/
{
if(vet[i]>vet[i+1])
{
aux=vet[i];
vet[i]=vet[i+1];
vet[i+1]=aux;
}
printf("%i", vet[i]);
}
/*fim da fase de processamento*/
break;
default:
break;
}
return 0;
}
His algorithm is wrong, as he only compares one number to the next (and he would need to compare it to all next to the end, considering that it is already ordered up to it). Reading tip: http://pt.wikipedia.org/wiki/Bubble_sort
– Luiz Vieira
I’m sure this one I wrote right at the end of the first stretch my dear.
– Leonardo V. De Gasperin
I don’t understand what you mean, my dear. :)
– Luiz Vieira