Estructuras Selectivas se utilizan para tomar decisiones lógicas
jhony97Documentos de Investigación12 de Noviembre de 2015
701 Palabras (3 Páginas)273 Visitas
ESTRUCTURAS SELECTIVAS
Las estructuras selectivas se utilizan para tomar decisiones lógicas, de ahí que suelen denominar también ESTRUCTURAS DE DECISIÓN Ó ALTERNATIVAS.
Las estructuras selectivas se representan usando las palabras en pseudocódigo (if,-then- else ó si-entonces-si no).
Las estructuras selectivas pueden ser:
- SIMPLES
- DOBLES
- MÚLTIPLES
- ALTERNATIVA SIMPLE(si-entonces/if-then)
PSEUDOCÓDIGO DIAGRAMA DE FLUJO
[pic 1][pic 2]
si
entonces[pic 4]
Fin_si[pic 5][pic 6][pic 7]
LENGUAJE C[pic 8]
if(condición)
accion1;
ó
if(condición){ //cuando sea un bloque de acciones, se deben usar llaves de inicio y fin
accion1;
accion2;
…
accionN;
}//cierra if
EJERCICIO:
- HACER UN ALGORITMO QUE CAPTURE UN NÚMERO ENTERO E INDIQUE SI ES POSITIVO. (HACERLO JUNTOS).
- REALIZAR UN ALGORITMO QUE CALCULE EL IMPORTE A PAGAR DE COLEGIATURA.SOLICITAR 3 CALIFICACIONES DE UN ALUMNO, SI EL PROMEDIO ES MAYOR DE 8.5 SE LE OTORGARÁ UNA BECA DEL 25%.LA MENSUALIDAD ES DE $1500.SE MOSTRARÁ LA MENSUALIDAD A PAGAR CON LA BECA INCLUIDA.
- ALTERNATIVA DOBLE (si-entonces- sino / if-then-else)
PSEUDOCÓDIGO DIAGRAMA DE FLUJO
[pic 9][pic 10]
si
entonces[pic 13][pic 14]
sino[pic 15]
fin_si[pic 16][pic 17][pic 18]
[pic 19]
[pic 20]
LENGUAJE C[pic 21][pic 22]
if(condición)
accion1;
else
accion2;
ó
if(condición){ //cuando sea un bloque de acciones, se deben usar llaves de inicio y fin
accion1;
accion2;
…
accionN;
}//cierra if
else {
accion1;
accion2;
…
accionN;
}//cierra else
3.- IF ANIDADOS Ó ALTERNATIVA MÚLTIPLE
(si-entonces- sino- si / if-then-else-if)
PSEUDOCÓDIGO DIAGRAMA DE FLUJO
[pic 23][pic 24]
si
entonces[pic 27][pic 28]
sino[pic 29]
si
...