Está en la página 1de 6

EJERCICIOS DESARROLLADOS

1. Cree un algoritmo que permita adivinar un nmero secreto generado por la computadora, en 10 intentos, si el numero que Ud. Ha ingresado es mayor que el secreto el sistema debe de arrogar Muy Alto, y en caso de que sea menor Muy Bajo; si el numero ingresado es igual debe de salir que adivin el nmero, el nmero secreto y el nmero de intentos. SOLUCIN Pseudocdigo Adivina_Numero Var. Entero : num_secreto, intentos, numingresado Inicio Intentos=1; num_secreto = Random(100); Escribir ("Adivine el nmero (de 1 a 100):"); Leer (num_ingresado); Mientras num_secreto<>num_ingresado & intentos <=10 Hacer Si num_secreto>num_ingresado Entonces Escribir ("Muy bajo"); Sino Escribir ("Muy alto"); Fin_Si Escribir ("Le quedan ",(10 intentos)," intentos:"); Leer (num_ingresado); intentos = intentos + 1; Fin_Mientras Si intentos=0 Entonces Escribir ("El nmero era: ",num_secreto); Sino Escribir ("Exacto! Usted adivin en ",intentos," intentos."); Fin_si Fin 2. Cree un algoritmo que permita sumar (S), restar (R), multiplicar (M), Dividir (D); dos nmeros segn el tipo de operacin ingresada. SOLUCIN Pseudocdigo Operaciones Var. Real : NUMERO1, NUMERO2, R; Cadena : OPERACIN; Carcter : OP; Inicio Escribir ("INGRESE NMERO 1 :"); LEER (NUMERO1); Escribir ("INGRESE NMERO 2 :"); LEER (NUMERO2); Escribir ("INGRESE OPERACIN :"); LEER (OP); Caso OP Sea 1: R=NUMERO1+NUMERO2; OPERACION="SUMA"; 2: R=NUMERO1-NUMERO2; OPERACION="RESTA"; 3: R=NUMERO1*NUMERO2; OPERACION="MULTIPLICACION"; 4: R=NUMERO1/NUMERO2;

Algoritmos y Estructuras de Datos | Ing. Richard Jhonson, Barrios Quispe

OPERACION="DIVISION"; Otro caso: R=0; OPERACIN= NO EXISTE; Fin_caso Escribir ("LA ", OPERACION, " DE LOS DOS NMEROS ES : ",R); Fin OTRA SOLUCIN Pseudocdigo Calculadora Var. Real : NUMERO1, NUMERO2, RESULTADO; Cadena : OPERACIN; Carcter : OP; Inicio Escribir ("INGRESE NMERO 1 :"); LEER (NUMERO1); Escribir ("INGRESE NMERO 2 :"); LEER (NUMERO2); Escribir ("INGRESE OPERACIN :"); LEER (OP); Si OP="S" Entonces RESULTADO=NUMERO1 + NUMERO2; OPERACION= "SUMA"; Sino Si OP="R" Entonces RESULTADO=NUMERO1 - NUMERO2; OPERACION= "RESTA"; Sino Si OP="M" Entonces RESULTADO=NUMERO1 * NUMERO2; OPERACION= "MULTIPLICACION"; Sino RESULTADO=NUMERO1 / NUMERO2; OPERACION= "DIVISION"; Fin_Si Fin_Si Fin_Si Escribir ("LA ", OPERACION, " DE LOS DOS NUMEROS ES : ",RESULTADO); Fin 3. Cree un Pseudocdigo y diagrama de flujo del siguiente enunciado: Un restaurant ofrece un descuento del 10% para consumos de hasta S/ 30.00, un descuento de 20% para consumos mayores y para ambos casos se aplica el Impuesto General a las ventas (IGV). Determinar el Importe a Pagar por lo consumido, mostrando todos los importes. SOLUCIN Pseudocdigo Restaurant Var. Real : CONSUMO, DSCTO, IGV, IMPORTE; Inicio Escribir "INGRESE EL CONSUMO :"; Leer CONSUMO; Si CONSUMO>30 Entonces DSCTO=0.20*CONSUMO; Sino DSCTO=0.10*CONSUMO; Fin_Si IGV=0.19*CONSUMO; IMPORTE=CONSUMO-DSCTO+IGV; Escribir "EL CONSUMO HA SIDO : ", CONSUMO, " NUEVOS SOLES"; Escribir "OBTUVO UN DESCUENTO DE : " , DSCTO, " NUEVOS SOLES";

Algoritmos y Estructuras de Datos | Ing. Richard Jhonson, Barrios Quispe

Escribir "SE LE APLIC UN I.G.V. DE : ", IGV, " NUEVOS SOLES"; Escribir "EL TOTAL A PAGAR ES : ", IMPORTE, " NUEVOS SOLES"; Fin 4. Cree un algoritmo que permita calcular el rea de un tringulo, en base a la frmula: Area= base * Altura /2 SOLUCIN Pseudocdigo Area_Tringulo Var. Entero : base, altura; Real : area; Inicio Escribir ("Ingrese base del tringulo : "); Leer (base); Escribir ("Ingrese la altura del tringulo : "); Leer (altura); area= (base*altura/2); Escribir ("El rea del tringulo es : ", area); Fin Cree un algoritmo que permita sumar los 10 primeros nmeros ingresados por teclado: SOLUCIN Pseudocdigo Suma Var. Real : suma, numero; Entero : contador Inicio contador= 1; suma= 0; Repetir Escribir ("ingrese numero ",c,":"); Leer (numero); suma= suma + numero; contador= contador + 1; Hasta que contador= 11 Escribir ("la suma es: ", suma); Fin Cree un algoritmo que permita sumar los 10 primeros nmeros (110): SOLUCIN Pseudocdigo SUMA Var. Entero : Contador, Suma Inicio Suma=0; Contador=0; Repetir Suma= Suma + Contador; Contador= Contador + 1; Hasta que c= 10 Escribir ("La suma de los 10 primeros nmeros es: ", suma); Fin Cree un algoritmo que permita hallar el menor de 5 nmeros ingresados por teclado: SOLUCIN Pseudocdigo MENOR Var. Real : A, B, C, D, E, MENOR; Inicio MENOR= 0; Escribir ("INGRESE PRIMER NMERO"); Leer (A);

5.

6.

7.

Algoritmos y Estructuras de Datos | Ing. Richard Jhonson, Barrios Quispe

Escribir ("INGRESE SEGUNDO NMERO"); Leer (B); Escribir ("INGRESE TERCER NMERO"); Leer (C); Escribir ("INGRESE CUARTO NMERO"); Leer (D); Escribir ("INGRESE QUINTO NMERO"); Leer (E); MENOR=0; Si A=B Entonces MENOR=A; Sino MENOR=B; Fin_si Si MENOR<C Entonces MENOR=MENOR; Sino MENOR=C; Fin_si SI MENOR<D Entonces MENOR=MENOR; Sino MENOR=D; Fin_si Si MENOR<E Entonces MENOR=MENOR; Sino MENOR=E; Fin_si Escribir ("EL MENOR VALOR ES: ",MENOR); Fin 8. Cree un algoritmo que permita hallar el mayor de 5 nmeros ingresados por teclado: SOLUCIN Pseudocdigo NUMERO_MAYOR Var. Real : A, B, C, D, E, MAYOR; Inicio MAYOR= 0; Escribir ("INGRESE PRIMER NMERO"); Leer (A); Escribir ("INGRESE SEGUNDO NMERO"); Leer (B); Escribir ("INGRESE TERCER NMERO"); Leer (C); Escribir ("INGRESE CUARTO NMERO"); Leer (D); Escribir ("INGRESE QUINTO NMERO"); Leer (E); MAYOR=0; Si A>B Entonces MAYOR=A; Sino MAYOR=B; Fin_si Si MAYOR>C Entonces MAYOR=MAYOR; Sino MAYOR=C; Fin_si Si MAYOR>D Entonces MAYOR=MAYOR;

Algoritmos y Estructuras de Datos | Ing. Richard Jhonson, Barrios Quispe

Sino Mayor=D; FinSi Si MAYOR>E Entonces MAYOR=MAYOR; Sino MAYOR=E; Fin_si Escribir ("EL MAYOR NMERO ES : ",MAYOR); Fin 9. Utilizando la estructura repetir: Cree un Pseudocdigo (la parte declarativa y operativa) del siguiente enunciado: Ingresar las edades de las personas que asisten al II Congreso Regional de Ingeniera de Sistemas y determinar cuntas personas asistieron, la edad mayor y la edad menor de todas cuando se d por terminado el proceso y esto ocurre cuando al ingresar una edad su valor es cero (0). SOLUCIN PSEUDOCODIGO CONGRESO VAR. ENTERO: MAYOR, MENOR, EDAD, C INICIO C0 MAYOR0 MENOR0 REPETIR ESCRIBIR (INGRESE LA EDAD DE LA PERSONA) LEER (EDAD) C=C+1 SI MAYOR>EDAD ENTONCES MAYORMAYOR SINO MAYOREDAD FIN_SI SI MENOR<EDAD MENORMENOR SINO MENOREDAD FIN_SI HASTA QUE EDAD=0 ESCRIBIR (LA CANTIDAD TOTAL DE ASISTENTES ES : , C) ESCRIBIR (LA EDAD MXIMA DE LOS ASISTENTES ES : , MAYOR) ESCRIBIR (LA EDAD MNIMA DE LOS ASISTENTES ES : , MENOR) FIN

10. Utilizando la estructura mientras: Cree un Pseudocdigo (la parte declarativa y operativa) del siguiente enunciado: Determinar la suma de los N primeros trminos de la serie de Fibonacci, y mostrar sus valores considerando que N sea mayor que 1. La secuencia de la serie es la siguiente: 0, 1, 1, 2, 3, 5, 8, 13, SOLUCIN PSEUDOCODIGO FIBONACCI VAR ENTERO: N, AUX, FIB, FIB1, CONT INICIO ESCRIBIR (INGRESE EL LIMITE DE LA SERIE) LEER (N) AUX0 FIB11 FIB0 CONT1 MIENTRAS CONT<=N HACER FIB FIB1 + AUX

Algoritmos y Estructuras de Datos | Ing. Richard Jhonson, Barrios Quispe

AUX<- FIB1 FIB1<- FIB CONT CONT +1 FIN_MIENTRAS ESCRIBIR ("EL N-SIMO : ", N, " TRMINO DE LA SERIE DE FIBONACCI ES: ", FIB); FIN 11. Utilizando la estructura desde (para): Cree un Pseudocdigo (la parte declarativa y operativa) del siguiente enunciado: Determinar la N-sima potencia de 2. Ejm: 20 = 1, 21 = 2, 22 = 4, 23 = 8, , 2n = X SOLUCIN PSEUDOCODIGO POTENCIA_N_DE_2 VAR ENTERO: N, POT, I INICIO ESCRIBIR ("INGRESE EL EXPONENTE N"); LEER (N); POT<-1; SI N=0 ENTONCES POT<-1; SINO PARA I<-1 HASTA N CON PASO 1 HACER POT<- POT * 2; FINPARA FINSI ESCRIBIR ("LA POTENCIA N-SIMA: ", N, " DE 2 ES: ", POT); FIN 12. Desarrolle cada uno de los tems dados para el trabajo con las Cadenas de Caracteres. T Per campen!, Per campen!; es el grito que repite la aficin X Alexander pato es un jugador brasileo a) Longitud (T) + Longitud (X) = b) Concatenar(subcadena (T, 1, 5), , subcadena(X, 4, 4) = c) X borrar (T, 1, 6) = SOLUCIN a) 103 b) Per xand c) campen!, Per campen!; es el grito que repite la aficin 13. Desarrolle cada uno de los tems dados para el trabajo con las Cadenas de Caracteres. T Calma, calma, que no cunda el pnico X Camarn que se duerme se lo lleva la corriente W En boca cerrada no entran moscas a) Longitud (T) = b) Longitud (X) = c) Longitud (W) = d) R Subcadena (X, 5, 12) = e) Concatenar(R, subcadena (T, 1, 5), , subcadena(W, 4, 4) = f) Q borrar(T, 12, 5) = g) X borrar (T, 1, 6) = h) F T + + X + + W = SOLUCIN a) 36 b) 46 c) 32 d) e) f) g) h) rn que se d rn que se dCalma boca Calma, calme no cunda el pnico calma, que no cunda el pnico Calma, calma, que no cunda el pnico calma, que no cunda el pnico En boca cerrada no entran moscas

Algoritmos y Estructuras de Datos | Ing. Richard Jhonson, Barrios Quispe

También podría gustarte