06.05.2013 Views

CONTENIDO DE LA LECCIÓN 18

CONTENIDO DE LA LECCIÓN 18

CONTENIDO DE LA LECCIÓN 18

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MIGUEL Á. TOLEDO MARTÍNEZ<br />

INSERCIÓN ELEMENTOS <strong>DE</strong> ARREGLOS CON EL USO <strong>DE</strong> CICLOS<br />

La desventaja obvia al usar asignaciones directas para insertar elementos de arreglos es<br />

que se requiere un enunciado de asignación separado para llenar cada posición del arreglo. Puede<br />

automatizar el proceso de inserción usando una estructura de ciclo. Aunque cualquiera de las tres<br />

estructuras de ciclo (while, do/while, for) se puede emplear, la estructura for es la más común. A<br />

continuación está el formato general para el uso de un ciclo for:<br />

INSERCIÓN <strong>DE</strong>NTRO <strong>DE</strong> UN ARREGLO UNIDIMENSIONAL CON EL USO <strong>DE</strong> UN CICLO for<br />

Considere el siguiente programa:<br />

for(int indice = 0; indice < tamaño del arreglo; ++indice)<br />

<br />

//LLENADO <strong>DE</strong> UN ARREGLO CON UN CICLO for<br />

#include // Para cin y cout<br />

// <strong>DE</strong>C<strong>LA</strong>RA EL TAMAÑO <strong>DE</strong>L ARREGLO<br />

const int MAX = 10;<br />

void main(void)<br />

{<br />

int muestra[MAX]; // <strong>DE</strong>FINE UN ARREGLO ENTERO<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!