PROGRAMAS ESTRUCTURADOS LENGUAJE C

6
Capítulo 3 Desarrollo de Programas Estructurados

description

PROGRAMAS ESTRUCTURADOS LENGUAJE C

Transcript of PROGRAMAS ESTRUCTURADOS LENGUAJE C

Page 1: PROGRAMAS ESTRUCTURADOS LENGUAJE C

Capítulo 3

Desarrollo de Programas Estructurados

Page 2: PROGRAMAS ESTRUCTURADOS LENGUAJE C

Desarrollo de Programas Estructurados

• Sentencias Repetitivas:– for …– while …– do.. while …

Page 3: PROGRAMAS ESTRUCTURADOS LENGUAJE C

Conceptos Básicos

Repetición Indefinida

• No se conoce el número de veces que se realizará la repetición.

• Se utiliza un dato "Centinela", la cual indica el "final de la ejecución de la repetición". Por ejemplo: presione 0 para finalizar el programa.

Page 4: PROGRAMAS ESTRUCTURADOS LENGUAJE C

while (condicion)

{

sentencias;

}

Sentencia Repetitiva: while

Page 5: PROGRAMAS ESTRUCTURADOS LENGUAJE C

• La sentencia for:

• Es muy similar a:

for (i=1; i<=10; i++){

/*cuerpo*/}

Aquí debe inicializarse la variable índice.

Relación entre el for y el while

Inicialización de índice;while (condicion){

sentencias;incremento/decremento;

}

for (inicio; condicion; inc/dec){

sentencias;}

i = 1;while (i <= 10){

/*cuerpo*/i++;

}Aquí debe realizarse el incremento de i.

Page 6: PROGRAMAS ESTRUCTURADOS LENGUAJE C

Tarea• Escriba un programa que muestre una tabla de

multiplicar del 1 al 10, con el siguiente formato.

1*1

1*2

1*3

1*4

..

1*10

5*1

5*2

5*3

5*4

..

5*10

1

2

3

4

5

6

7

8

9

10

1 2 3 4 5 6 7 8 9 10