-1
I’m trying to make this problem, but always the result goes wrong.
"Make a program that creates a user-filled 10-position array. Scan the vector and whenever the value of position i of the vector is less than the value of position i+1 you must change them."
#include <stdio.h>
int main()
{
int i,vet[10],aux;
aux = 0;
for(i=0;i<10;i++)
{
printf("Digite um valor:\n");
scanf("%d",&vet[i]);
}
for(i=0;i<9;i++)
{
if(vet[i]<vet[i+1])
{
aux = vet[i];
vet[i] = vet[i+1];
vet[i+1] = aux;
}
}
printf("\n");
for(i=0;i<10;i++)
{
printf("%d\n",vet[i]);
}
return 0;
}
You are checking your vector only once. If there is any change you have to check the whole vector again, until no change occurs. So we missed a loop.
– anonimo