PROGRAMAS ESTRUCTURADOS LENGUAJE C
-
Upload
gustavo-salazar -
Category
Education
-
view
17.655 -
download
3
description
Transcript of PROGRAMAS ESTRUCTURADOS LENGUAJE C
Desarrollo de Programas Estructurados
• Sentencias Repetitivas:– for …– while …– do.. while …
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.
while (condicion)
{
sentencias;
}
Sentencia Repetitiva: while
• 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.
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