antonio ryan Posted March 23, 2020 at 08:57 PM Share Posted March 23, 2020 at 08:57 PM Pessoal, boa tarde . Sou iniciante em linguagem C, e por isso estou com dificuldades pra conseguir identificar o erro. Me digam por favor o que está errado nesse código, e me digam como resolver!! professor me passou 1 exercicios para resolver e não estou conseguindo achar o erro! 1º Apresente o funcionamento do algoritmo de ordenação INSERÇÃO, iteração por iteração, dos seguintes vetores: [50,20,10,15,21]; #include <stdio.h> void sort(int *arr, int size); int main(){ int a [] = {50, 20, 10, 15, 21}; sort(a, 10); for(int i = 0; i < 10; i++) printf("%d\n", a); return 0; } void sort(int *arr, int size){ int x, y, value; for(x = 10; x < size; x ++){ value = arr[x]; for(y = x - 10; y >= 0 && arr[y] > value; y --){ arr[y+1] = arr[y]; } arr[y+1] = value; } } Link to comment Share on other sites More sharing options...
Marioh Posted March 23, 2020 at 09:10 PM Share Posted March 23, 2020 at 09:10 PM No printf falta os colchetes no 'a' como a[ i ] Link to comment Share on other sites More sharing options...
Marioh Posted March 23, 2020 at 09:27 PM Share Posted March 23, 2020 at 09:27 PM creio que a logica do teu primeiro for esteja errada tbm pq ele nunca vai ser executado com valores menores que 11. Talvez o teu x deva ser 0 ? Alem disso tu esta lendo mais do que teu vetor e assim tu vai pegar lixo na memoria. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.