SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Tema 4 Estructuras de Control Iterativas
Estructuras iterativas ,[object Object],[object Object],[object Object]
Iteraciones en c ,[object Object],[object Object],[object Object]
Sentencia   while ,[object Object],[object Object],[object Object],[object Object],¿condición? V F Bloque de instrucciones
S emántica de   while ,[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ejemplo
Ejemplo
Iteraciones en c ,[object Object],[object Object],[object Object]
Sentencia   do-while ,[object Object],[object Object],[object Object],[object Object],¿condición? V F Bloque de instrucciones
S emántica de   do- while ,[object Object],[object Object],[object Object],[object Object],[object Object]
Ejemplo ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ejemplo
Diseño  de la iteración ,[object Object],[object Object],[object Object],[object Object]
Diseño  de la iteración ,[object Object],[object Object],[object Object],[object Object],[object Object]
Diseño  de la iteración ,[object Object],[object Object],[object Object]
Ejemplo resuelto ,[object Object],[object Object]
Control de la iteración ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Proceso de la iteración ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algoritmo Inicialización Control Proceso INICIO LEER ( a ) b =1 b <=10 ESCRIBIR  a * b Saltar de línea b = b +1 V F FIN
Código ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Comprobación (trazas) 20 5 4 16 4 4 24 6 4 8 2 4 12 3 4 4 1 4 .. .. .. 10 b 40 4 c a
Ejemplo/ ejercicio 1 ,[object Object],[object Object],[object Object]
Algoritmo (con do-while) F Calcular  num  en pesetas Escribir resultado en pesetas ¿Qué deseas (P/E)?    opc ¿ opc  == ‘P’? V ¿Qué número?   num Calcular  num  en euros Escribir resultado en euros ¿Más números (S/N)?   resp ¿ resp  == ‘S’? V F FIN
Algoritmo (con  while ) resp=‘S’ Calcular  num  en pesetas Escribir resultado en pesetas ¿Más números (S/N)?   resp F ¿ opc  == ‘P’? V Calcular  num  en euros Escribir resultado en euros ¿Qué deseas (P/E)?    opc ¿Qué número?   num ¿ resp  == ‘S’? V F FIN
Ejemplo/ ejercicio 2 ,[object Object],Leer  Numero ¿Potencia< Numero ? Escribir Potencia V F Potencia = 1 Potencia = Potencia * 2
Código (con  while ) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ejemplo/ ejercicio 3 ,[object Object],Leer  car  (un carácter) ¿ car  !=‘.’? Escribir num V F num = 1 num = num +1 Leer  car
Código (con  while ) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Código (con  do-while ) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ejercicios ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Iteraciones en c ,[object Object],[object Object],[object Object]
Sentencia   for ,[object Object],[object Object],[object Object],[object Object],¿condición? V F Bloque de instrucciones Inicialización Actualización
Semántica  de   for ,[object Object],[object Object],[object Object],[object Object],[object Object]
Equivalencia  for  -  while inicialización; while ( condición ) { bloque_instrucciones; actualización: } for ( inicialización ;  condición;   actualización ) { bloque_instrucciones; }
Ejemplo ,[object Object],scanf (“%d”, &n) i=1; while (i<=n) { printf(“ %d”, 2*i); i= i+1; } scanf (“%d”, &n) for (i=1;  i<=n;  i= i+1) { printf(“ %d”, 2*i); }
Estructuras  iterativas ,[object Object],[object Object],[object Object],[object Object]
Ejercicios
Ejercicio  factorial ,[object Object],[object Object]
while Leer el número     num ¿ num  == 0? fact = 1 Escribir resultado ¿ num  <0? No se puede Calcular  num ! fact = 1 i = 1 ¿ i  <=  num ? fact = fact * i i = i + 1 Escribir fact V V V F F F
for for (i=1;i<=num;i=i+1) {fact=fact*i;} Leer el número     num ¿ num  == 0? fact = 1 Escribir resultado ¿ num  <0? No se puede calcular  num ! fact = 1; Repetir desde que i vale 1 hasta que i valga  num , i=i+1; fact = fact * i; Escribir fact SI SI NO NO
Más ejercicios ,[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Logica Algoritmo 05 Repeticao
Logica Algoritmo 05 RepeticaoLogica Algoritmo 05 Repeticao
Logica Algoritmo 05 RepeticaoRegis Magalhães
 
Análisis de complejidad introducción notación big o
Análisis de complejidad   introducción notación big oAnálisis de complejidad   introducción notación big o
Análisis de complejidad introducción notación big oUVM
 
Exercicios resolvidos visu alg vetores
Exercicios resolvidos visu alg vetoresExercicios resolvidos visu alg vetores
Exercicios resolvidos visu alg vetoresWillians Miyabara
 
Ejemplos de algoritmos con estructuras repetitivas
Ejemplos de algoritmos con estructuras repetitivasEjemplos de algoritmos con estructuras repetitivas
Ejemplos de algoritmos con estructuras repetitivasJunior Solano de Arco
 
Estructuras repetitivas
Estructuras repetitivasEstructuras repetitivas
Estructuras repetitivasVictor Zapata
 
Arreglo de punteros
Arreglo de punterosArreglo de punteros
Arreglo de punterospedreror1
 
Material de Apoio de Algoritmo e Lógica de Programação
Material de Apoio de Algoritmo e Lógica de ProgramaçãoMaterial de Apoio de Algoritmo e Lógica de Programação
Material de Apoio de Algoritmo e Lógica de Programaçãorodfernandes
 
Egypt Vocabulary
Egypt VocabularyEgypt Vocabulary
Egypt Vocabularymemuflo
 
Practica 11 Laboratorio de Computación para Ingenieros FI
Practica 11 Laboratorio de Computación para Ingenieros FIPractica 11 Laboratorio de Computación para Ingenieros FI
Practica 11 Laboratorio de Computación para Ingenieros FIJorge Iván Alba Hernández
 
PHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de ControlePHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de ControleGeorge Mendonça
 
Aula Lógica de Programação - cap1
Aula Lógica de Programação - cap1 Aula Lógica de Programação - cap1
Aula Lógica de Programação - cap1 Cloves da Rocha
 
Instrucciones de control de salto
Instrucciones de control de saltoInstrucciones de control de salto
Instrucciones de control de saltoAbrirllave
 

Was ist angesagt? (20)

Logica Algoritmo 05 Repeticao
Logica Algoritmo 05 RepeticaoLogica Algoritmo 05 Repeticao
Logica Algoritmo 05 Repeticao
 
Arreglos
ArreglosArreglos
Arreglos
 
Análisis de complejidad introducción notación big o
Análisis de complejidad   introducción notación big oAnálisis de complejidad   introducción notación big o
Análisis de complejidad introducción notación big o
 
Exercicios resolvidos visu alg vetores
Exercicios resolvidos visu alg vetoresExercicios resolvidos visu alg vetores
Exercicios resolvidos visu alg vetores
 
Ejercicio en c
Ejercicio en cEjercicio en c
Ejercicio en c
 
Funcion printf
Funcion printfFuncion printf
Funcion printf
 
Ejemplos de algoritmos con estructuras repetitivas
Ejemplos de algoritmos con estructuras repetitivasEjemplos de algoritmos con estructuras repetitivas
Ejemplos de algoritmos con estructuras repetitivas
 
Estructuras repetitivas
Estructuras repetitivasEstructuras repetitivas
Estructuras repetitivas
 
Arreglo de punteros
Arreglo de punterosArreglo de punteros
Arreglo de punteros
 
Estrutura de dados em Java - Pilhas
Estrutura de dados em Java - PilhasEstrutura de dados em Java - Pilhas
Estrutura de dados em Java - Pilhas
 
Material de Apoio de Algoritmo e Lógica de Programação
Material de Apoio de Algoritmo e Lógica de ProgramaçãoMaterial de Apoio de Algoritmo e Lógica de Programação
Material de Apoio de Algoritmo e Lógica de Programação
 
15 Curso de POO en java - estructuras repetitivas
15 Curso de POO en java - estructuras repetitivas15 Curso de POO en java - estructuras repetitivas
15 Curso de POO en java - estructuras repetitivas
 
Egypt Vocabulary
Egypt VocabularyEgypt Vocabulary
Egypt Vocabulary
 
Apostila visualg
Apostila visualgApostila visualg
Apostila visualg
 
Practica 11 Laboratorio de Computación para Ingenieros FI
Practica 11 Laboratorio de Computación para Ingenieros FIPractica 11 Laboratorio de Computación para Ingenieros FI
Practica 11 Laboratorio de Computación para Ingenieros FI
 
PHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de ControlePHP 5.3 - Estruturas de Controle
PHP 5.3 - Estruturas de Controle
 
Aula Lógica de Programação - cap1
Aula Lógica de Programação - cap1 Aula Lógica de Programação - cap1
Aula Lógica de Programação - cap1
 
Instrucciones de control de salto
Instrucciones de control de saltoInstrucciones de control de salto
Instrucciones de control de salto
 
7.arreglos y vectores en c++
7.arreglos y vectores en c++7.arreglos y vectores en c++
7.arreglos y vectores en c++
 
Programación 1: cadenas en C
Programación 1: cadenas en CProgramación 1: cadenas en C
Programación 1: cadenas en C
 

Ähnlich wie while y do while

Introducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En CIntroducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En Cpainni
 
Clase lenguaje c
Clase lenguaje c Clase lenguaje c
Clase lenguaje c Mar15marian
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxxMar15marian
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxxMar15marian
 
Ucv 2015-1_fd_p_s1_estructuras repetitivas
 Ucv 2015-1_fd_p_s1_estructuras repetitivas Ucv 2015-1_fd_p_s1_estructuras repetitivas
Ucv 2015-1_fd_p_s1_estructuras repetitivasjcbp_peru
 
Estructuras De RepeticióN
Estructuras De RepeticióNEstructuras De RepeticióN
Estructuras De RepeticióNRegina Flores
 
Estructuras De RepeticióN
Estructuras De RepeticióNEstructuras De RepeticióN
Estructuras De RepeticióNRegina Flores
 
estructuras de repeticion
estructuras de repeticionestructuras de repeticion
estructuras de repeticionadark
 
ESTRUCTURAS DE CONTROL: BUCLES EN C++
ESTRUCTURAS DE CONTROL: BUCLES EN C++ESTRUCTURAS DE CONTROL: BUCLES EN C++
ESTRUCTURAS DE CONTROL: BUCLES EN C++die_dex
 
Sentencia de control
Sentencia de controlSentencia de control
Sentencia de controlStalyn Cruz
 
Introduccion a C++
Introduccion a C++Introduccion a C++
Introduccion a C++LenHugo
 
Programación de nivel básico 3. c2. p2.
Programación de nivel básico 3. c2. p2.Programación de nivel básico 3. c2. p2.
Programación de nivel básico 3. c2. p2.DENIRAMIREZANDRADE
 

Ähnlich wie while y do while (20)

Pr109 while
Pr109 whilePr109 while
Pr109 while
 
Estructura repetitiva
Estructura repetitivaEstructura repetitiva
Estructura repetitiva
 
Introducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En CIntroducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En C
 
Clase lenguaje c
Clase lenguaje c Clase lenguaje c
Clase lenguaje c
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxx
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxx
 
Guia4
Guia4Guia4
Guia4
 
Ucv 2015-1_fd_p_s1_estructuras repetitivas
 Ucv 2015-1_fd_p_s1_estructuras repetitivas Ucv 2015-1_fd_p_s1_estructuras repetitivas
Ucv 2015-1_fd_p_s1_estructuras repetitivas
 
Estructuras De RepeticióN
Estructuras De RepeticióNEstructuras De RepeticióN
Estructuras De RepeticióN
 
Estructuras De RepeticióN
Estructuras De RepeticióNEstructuras De RepeticióN
Estructuras De RepeticióN
 
Instruccion while bm
Instruccion while bmInstruccion while bm
Instruccion while bm
 
estructuras de repeticion
estructuras de repeticionestructuras de repeticion
estructuras de repeticion
 
ESTRUCTURAS DE CONTROL: BUCLES EN C++
ESTRUCTURAS DE CONTROL: BUCLES EN C++ESTRUCTURAS DE CONTROL: BUCLES EN C++
ESTRUCTURAS DE CONTROL: BUCLES EN C++
 
3 condicionales y ciclos
3 condicionales y ciclos3 condicionales y ciclos
3 condicionales y ciclos
 
Clase 8
Clase 8Clase 8
Clase 8
 
Sentencia de control
Sentencia de controlSentencia de control
Sentencia de control
 
Introduccion a C++
Introduccion a C++Introduccion a C++
Introduccion a C++
 
03 iteracion
03 iteracion03 iteracion
03 iteracion
 
Programación de nivel básico 3. c2. p2.
Programación de nivel básico 3. c2. p2.Programación de nivel básico 3. c2. p2.
Programación de nivel básico 3. c2. p2.
 
pptx.s3.pdf
pptx.s3.pdfpptx.s3.pdf
pptx.s3.pdf
 

Mehr von Gustavo Medina

Mehr von Gustavo Medina (6)

Infografia
InfografiaInfografia
Infografia
 
El sorbo
El sorboEl sorbo
El sorbo
 
Consultorias el jardin. ultimo
Consultorias el jardin. ultimoConsultorias el jardin. ultimo
Consultorias el jardin. ultimo
 
Reciclaje
ReciclajeReciclaje
Reciclaje
 
Tema 4 iterativas
Tema 4   iterativasTema 4   iterativas
Tema 4 iterativas
 
Tema 4 iterativas
Tema 4   iterativasTema 4   iterativas
Tema 4 iterativas
 

while y do while

  • 1. Tema 4 Estructuras de Control Iterativas
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 8.
  • 9.
  • 10.
  • 11.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Algoritmo Inicialización Control Proceso INICIO LEER ( a ) b =1 b <=10 ESCRIBIR a * b Saltar de línea b = b +1 V F FIN
  • 20.
  • 21. Comprobación (trazas) 20 5 4 16 4 4 24 6 4 8 2 4 12 3 4 4 1 4 .. .. .. 10 b 40 4 c a
  • 22.
  • 23. Algoritmo (con do-while) F Calcular num en pesetas Escribir resultado en pesetas ¿Qué deseas (P/E)?  opc ¿ opc == ‘P’? V ¿Qué número?  num Calcular num en euros Escribir resultado en euros ¿Más números (S/N)?  resp ¿ resp == ‘S’? V F FIN
  • 24. Algoritmo (con while ) resp=‘S’ Calcular num en pesetas Escribir resultado en pesetas ¿Más números (S/N)?  resp F ¿ opc == ‘P’? V Calcular num en euros Escribir resultado en euros ¿Qué deseas (P/E)?  opc ¿Qué número?  num ¿ resp == ‘S’? V F FIN
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. Equivalencia for - while inicialización; while ( condición ) { bloque_instrucciones; actualización: } for ( inicialización ; condición; actualización ) { bloque_instrucciones; }
  • 35.
  • 36.
  • 38.
  • 39. while Leer el número  num ¿ num == 0? fact = 1 Escribir resultado ¿ num <0? No se puede Calcular num ! fact = 1 i = 1 ¿ i <= num ? fact = fact * i i = i + 1 Escribir fact V V V F F F
  • 40. for for (i=1;i<=num;i=i+1) {fact=fact*i;} Leer el número  num ¿ num == 0? fact = 1 Escribir resultado ¿ num <0? No se puede calcular num ! fact = 1; Repetir desde que i vale 1 hasta que i valga num , i=i+1; fact = fact * i; Escribir fact SI SI NO NO
  • 41.