Você está na página 1de 12

LABORATORIO # 3 CICLOS ANIDADOS

GRUPO: 16

INTEGRANTES:

MOLLINEDO FRANCO MILENA


MONTAO FLORES DIANA ERIKA
MONTAO ROJAS ALEX
MORENO FERNANDEZ CARLA PATRICIA
MOYE RIVERA RODDY RODOLFO

COMENTARIOS: En este trabajo pudimos aprender que se puede implementar ms ciclos


dentro de un ciclo, pero en tiempo de ejecucin es mucho mayor para estos.
Adems, se pudo ver que se puede optimizar algunos de estos ciclos para un menor
tiempo de ejecucin.

CODIGO FUENTE:

EN PASCAL

//#1

Procedure Tabla(n:Integer);

var i,j:Integer;

Begin

i:=1;

while i<=n do

Begin

j:=1;

while j<=n do

Begin

writeln(j,'*',i,'=',j*i);

j:=j+1;

End;

writeln;

i:=i+1;

End;

End;
//#2

Procedure TablaAscDesc(n:Integer);

var i,j:Integer;

Begin

i:=1;

while i<=n do

Begin

j:=n;

while j>0 do

Begin

writeln(i,'*',j,'=',j*i);

j:=j-1;

End;

writeln;

i:=i+1;

End;

End;

//#3

Procedure TablaPares(n:Integer);

var i,j:Integer;

Begin

i:=2;

while i<=n do

Begin

j:=2;

while j<=n do

Begin

writeln(j,'*',i,'=',j*i);

j:=j+2;

End;

writeln;

i:=i+2;

End;

End;
//#4

Procedure TablaParImpar(n:Integer);

var i,j:Integer;

Begin

i:=2;

while i<=n do

Begin

j:=1;

while j<=n do

Begin

writeln(i,'*',j,'=',j*i);

j:=j+2;

End;

writeln;

i:=i+2;

End;

End;

//#5

//AUXILIAR

Function Primo(n:Integer):Boolean;

var i,c:Integer;

Begin

i:=1; c:=0;

while i<=n do

Begin

if n Mod i = 0 then c:=c+1;

i:=i+1;

End;

result:= c=2;

End;

Procedure TablaPrimos(n:Integer);

var i,j:Integer;

Begin

i:=1;
while i<=n do

Begin

j:=1;

while (j<=n) And (Primo(i)=True) do

Begin

If Primo(j)=True Then writeln(i,'*',j,'=',j*i);

j:=j+1;

End;

writeln;

i:=i+1;

End;

End;

//#6.1 T(n)=n*n

Procedure TablaIguales(n:Integer);

var i,j:Integer;

Begin

i:=1;

while i<=n do

Begin

j:=1;

while j<=n do

Begin

If j = i Then writeln(i,'*',j,'=',j*i);

j:=j+1;

End;

i:=i+1;

End;

End;

//#6.2 T(n)=n

Procedure TablaIguales2(n:Integer);

var i,j:Integer;

Begin

i:=1; j:=1;

while i<=n do
Begin

writeln(i,'*',j,'=',i*j);

i:=i+1;

j:=j+1;

End;

End;

//#7 T(n)=n*n*n

Procedure Pitagoras(n:Integer);

var a,b,c:Integer;

Begin

a:=1;

while a<=n do

Begin

b:=1;

while b<=n do

Begin

c:=1;

while c<=n do

Begin

if (a*a + b*b)= (c*c) then writeln(a,' ',b,' ',c);

c:=c+1;

End;

b:=b+1;

End;

a:=a+1;

End;

End;

//#8 T(n)<n*n*n

Procedure PitagorasMejorado(n:Integer);

var a,b,c:Integer;

Begin

a:=1;

while a<=n do
Begin

b:=1;

while b<=a do

Begin

c:=b;

while (a*a + b*b)>(c*c) do

Begin

c:=c+1;

End;

if (a*a + b*b)= (c*c) then

Begin

writeln(a,' ',b,' ',c);

writeln(b,' ',a,' ',c);

End;

b:=b+1;

End;

a:=a+1;

End;

End;

EN JAVA

//#1

public static void tabla(int n){

int i=1;

while(i<=n){

int j=1;

while(j<=n){

System.out.println(i+"x"+j+"="+i*j);

j++;

System.out.println();

i++;

}
//#2

public static void tablaAscDesc(int n){

int i=1;

while(i<=n){

int j=n;

while(j>0){

System.out.println(i+"x"+j+"="+i*j);

j--;

System.out.println();

i++;

//#3

public static void tablaPares(int n){

int i=2;

while(i<=n){

int j=2;

while(j<=n){

System.out.println(i+"x"+j+"="+i*j);

j=j+2;

System.out.println();

i=i+2;

//#4

public static void tablaParImpar(int n){

int i=2;

while(i<=n){

int j=1;

while(j<=n){

System.out.println(i+"x"+j+"="+i*j);

j=j+2;
}

System.out.println();

i=i+2;

//#5

public static void tablaPrimos(int n){

int i=1;

while(i<=n){

int j=1;

while(j<=n && primo(i)==true){

if(primo(j)==true) System.out.println(i+"x"+j+"="+i*j);

j++;

System.out.println();

i++;

//AUXILIAR

public static boolean primo(int n){

int i=1,c=0;

while(i<=n){

if(n % i == 0) c=c+1;

i++;

return c==2;

//#6.1 T(n)=n*n

public static void tablaIguales(int n){

int i=1;

while(i<=n){

int j=1;

while(j<=n){

if(i==j) System.out.println(i+"x"+j+"="+i*j);
j++;

System.out.println();

i++;

//#6.2 T(n)=n

public static void tablaIguales2(int n){

int i=1, j=1;

while(i<=n){

System.out.println(i+"x"+j+"="+i*j);

i++; j++;

//#7 T(n)=n*n*n

public static void pitagoras(int n){

int a=1;

while(a<=n){

int b=1;

while(b<=n){

int c=1;

while(c<=n){

if(a*a + b*b == c*c)

System.out.println(a+"\t"+b+"\t"+c);

c++;

b++;

a++;

//#8 T(n)<n*n*n

public static void pitagorasMejorado(int n){

int a=1;
while(a<=n){

int b=a;

while(b<=n){

int c=b;

while(a*a + b*b > c*c){

c++;

if(a*a + b*b == c*c){

System.out.println(a+"\t"+b+"\t"+c);

System.out.println(b+"\t"+a+"\t"+c);

b++;

a++;

EN VISUAL BASIC

'#1

Sub Tabla(n As Integer)


Dim i = 1
While i <= n
Dim j = 1
While j <= n
Console.WriteLine(i & "*" & j & "=" & j * i)
j = j + 1
End While
Console.WriteLine()
i = i + 1
End While
End Sub
'#2
Sub TablaAscDesc(n As Integer)
Dim i = 1
While i <= n
Dim j = n
While j > 0
Console.WriteLine(i & "*" & j & "=" & j * i)
j = j - 1
End While
Console.WriteLine()
i = i + 1
End While
End Sub
'#3
Sub TablaPares(n As Integer)
Dim i = 2
While i <= n
Dim j = 2
While j <= n
Console.WriteLine(i & "*" & j & "=" & j * i)
j = j + 2
End While
Console.WriteLine()
i = i + 2
End While
End Sub
'#4
Sub TablaParImpar(n As Integer)
Dim i = 2
While i <= n
Dim j = 1
While j <= n
Console.WriteLine(i & "*" & j & "=" & i * j)
j = j + 2
End While
Console.WriteLine()
i = i + 2
End While
End Sub
'#5
Sub TablaPrimos(n As Integer)
Dim i = 1
While i <= n
Dim j = 1
While j <= n And Primo(i) = True
If Primo(j) = True Then
Console.WriteLine(i & "*" & j & "=" & j * i)
End If
j = j + 1
End While
Console.WriteLine()
i = i + 1
End While
End Sub
'AUXILIAR
Function Primo(n As Integer) As Boolean
Dim i = 1, c = 0
While i <= n
If n Mod i = 0 Then c = c + 1
i = i + 1
End While
Return c = 2
End Function
'#6.1 T(n)=n*n
Sub TablaIguales(n As Integer)
Dim i = 1
While i <= n
Dim j = 1
While j <= n
If j = i Then Console.WriteLine(i & "*" & j & "=" & j * i)
j = j + 1
End While
i = i + 1
End While
End Sub
'#6.2 T(n)=n
Sub TablaIguales2(n As Integer)
Dim i = 1, j = 1
While i <= n
Console.WriteLine(i & "*" & j & "=" & j * i)
i = i + 1
j = j + 1
End While
End Sub
'#7 T(n)=n*n*n
Sub Pitagoras(n As Integer)
Dim a = 1
While a <= n
Dim b = 1
While b <= n
Dim c = 1
While c <= n
If a * a + b * b = c * c Then
Console.WriteLine(a & " " & b & " " & c & " ")
End If
c = c + 1
End While
b = b + 1
End While
a = a + 1
End While
End Sub

'#8 T(n)<n*n*n
Sub PitagorasMejorado(n As Integer)
Dim a = 1
While a <= n
Dim b = a
While b <= n
Dim c = b
While a * a + b * b > c * c
c = c + 1
End While
If a * a + b * b = c * c Then
Console.WriteLine(a & " " & b & " " & c & " ")
Console.WriteLine(b & " " & a & " " & c & " ")
End If
b = b + 1
End While
a = a + 1
End While
End Sub