Está en la página 1de 5

UNIVERSIDAD DE PANAMÁ

FACULTAD DE INFORMÁTICA, ELECTRÓNICA Y COMUNICACIÓN

LABORATORIO #2 DE PROLOG

ELABORADO POR:
Iván Serrano

FECHA DE ENTREGA
Miércoles 11 de mayo

1. DESPLEGAR LOS ENTEROS ENTRE 30 Y 50 ACOMPAÑADOS DE SU POTENCIA


CUADRADA Y RAIZ CUADRADA

predicates
ciclo(integer)

goal
clearwindow,
ciclo(30).

clauses
ciclo(X) if X>50, !;
Pote=X*X, Raiz=sqrt(X), write(X," ",Pote," ",Raiz,"\n"),
X1=X+1, ciclo(X1).
2. DESPLEGAR MULTIPLOS DE 4 ENTRE 20 Y 60
predicates
ciclo(integer)

goal
clearwindow,
ciclo(20).

clauses
ciclo(Cont) if Cont>60, !;
Cont mod 4 = 0,
write(Cont,"\n"),
Cont1=Cont+1,ciclo(Cont1);
Cont1 = Cont + 1, ciclo(Cont1).

3. CONSTRUIR LA TABLA DE DIVIDIR QUE EL USUARIO INDIQUE

predicates
ciclo(integer,integer)

goal
clearwindow,
write(" Numero: "), readint(Num),
ciclo(1,Num).

clauses

ciclo(X,Num) if X>12, !;
Res = Num/X,
write(Num,"/",X,"= ",Res,"\n"), X1=X+1, ciclo(X1,Num).

4. ESCRIBIR UN PROGRAMA QUE CALCULE LA SUMA DE CADA TERCER ENTERO, COMENZANDO


CON I=2 (ES DECIR, CALCULE LA SUMA DE 2 + 5 + 8 + 11 + …) PARA TODOS LOS VALORES DE I
MENORES QUE 100

predicates
ciclo(integer, integer)

goal
clearwindow,
ciclo(2,0).

clauses
ciclo(Cont, Acum) if Cont>100, write("Suma= ",Acum), !;
write(Cont," "),
Suma1 = Acum+Cont, Cont1= Cont+3, ciclo(Cont1,Suma1).
5. LEA UN NÚMERO Y GENERE EL TRIANGULO DE ASTERISCOS.
EJEMPLO: SI UD. INSERTA 3 DEBERÁ DESPLEGAR
*
**
***
predicates
lectura(integer, integer)
ciclo(integer, integer)

goal
clearwindow,
write("Ingrese un numero: "), readint(Num),
ciclo(1,Num).

clauses
ciclo(X, Num) if X>Num, !;
lectura(1, X), write("\n"), X1=X+1, ciclo(X1,Num).

lectura(Z, X) if Z>X, !;
write("*"), Z1 = Z+1, lectura(Z1, X).
6. LEA UN NÚMERO Y GENERE EL TRIANGULO DE ASTERISCOS.
EJEMPLO SI UD. INSERTA 3 DEBERÁ DESPLEGAR
 * *
 *
 *

predicates
lectura(integer, integer)
ciclo(integer, integer)

goal
clearwindow,
write("Ingrese un numero: "), readint(Num),
ciclo(Num, 1).

clauses
ciclo(X, Num) if X<1, !;
lectura(1, X), write("\n"), X1=X-1, ciclo(X1,Num).

lectura(Z, X) if Z>X, !;
write("*"), Z1 = Z+1, lectura(Z1, X).

También podría gustarte