Algoritmo a ordenar
Order the lines to search for a value in an array. Use position = -1 as a sentinel, break when found, and then report the result with an if/else.
Arrastra las lineas o usa los botones de flecha para reordenarlas. Cuando creas que estan en el orden correcto, tocas Verificar ordenamiento.
- 1
#include <stdio.h> - 2
int main() { - 3
int numbers[6] = {8, 14, 21, 14, 35, 42}; - 4
int i; - 5
int target = 14; - 6
int position = -1; - 7
for (i = 0; i < 6; i = i + 1) { - 8
if (numbers[i] == target) { - 9
position = i; - 10
break; - 11
} - 12
} - 13
if (position != -1) { - 14
printf("The value %d was found at position %d.\n", target, position); - 15
} else { - 16
printf("The value %d was not found.\n", target); - 17
} - 18
return 0; - 19
}
Ordena todas las lineas y despues toca Verificar ordenamiento.