lunes, 21 de mayo de 2012

Para que veais que no ha resultado nada facil Pascal, aqui os voy a dejar los algoritmos escritos de todos los programas que hemos realizado para que os animeis a probralos en casa.

EL PRIMER EJERCICIO CONSISTIA EN ESCRIBIR TU NOMBRE Y EL ORDENADOR TE DABA LA BIENVENIDA Y TE HACIA UNA PREGUNTA. EL PROGRAMA SE LLAMABA HOLA2:


program Saludo2;
uses crt;
var
c:char;
nom:ansistring;
begin
clrscr;
writeln('Hola,¨como te llamas?');
readln(nom);
writeln('Buenos dias',nom,'¨Eres del VCF? (s/n)');
readln(c);
if c='s' then
writeln('Fenomenal')
else if c='n'
then
writeln('Muy mal');
readkey;
end.
















EL SIGUIENTE EJERCICO QUE HICIMOS TRATABA SOBRE UN PROBLEMA DE FISICA RELACIONADO CON EL TEMA DE OPTICA. EL NOMBRE DEL PROGRAMA ES OPTICA:

program Optica;
uses crt;
var
So:real;
f:real;
Si:real;
Al:real;
c:real;
begin
clrscr;
writeln('Introduce la distancia objeto(So>0)');
readln(So);
writeln('Introduce la distancia focal(f>0)');
readln(f);
c:=(1/f)-(1/So);

if So=f
then
writeln('No se forma imagen')
else
begin

Si:=1/c;
writeln('La distancia imagen es igual a:',Si:0:2);
Al:=-Si/So;
if Si>0
then
writeln('Imagen real')
else
writeln('Imagen virtual');

writeln('La altura lateral resultante:',Al:0:2);
if Al>0
then
writeln('Derecha')
else
writeln('Invertida');

if abs(Al)>1
then
writeln('Aumentada')
else
begin
if abs(Al)=1
then
writeln('Natural')
else
writeln('Reducida');
end;
end;
Readkey;
End.


A CONTINUACION, EL SIGUIENTE PROGRAMA CONSISTIA EN INSERTAR UN NUMERO Y EL NUMERO QUE TU INSERTASES TENIA QUE COINCIDIR CON UN NUMERO QUE EL ORDENADOR HABIA PENSADO. EL NOMBRE DEL PROGRAMA ES ADIVINAR:

program Adivinar;
uses crt;
var
nom:ansistring;
num:integer;
num1:integer;
begin
clrscr;
writeln('Hola,¨c¢mo te llamas?');
readln(nom);
writeln('Hola',nom,'Adivina un numero del 1 al 10');
readln(num);
randomize;
num1:=random(9)+1;
if num<0
then
writeln('No has hecho caso a las indicaciones')
else
begin
if(num)>10
then
writeln('No has hecho caso a las indicaciones')
else
if (num)=(num1)
then
writeln('Muy bien. Has acertado el numero')
else
writeln('Lo siento. Tu numero no concuerda con el del ordenador');

end;
readkey;
end.


EN EL PROGRAMA SIGUIENTE EMPEZAMOS CON LOS BUCLES. ESTA VEZ TENIAMOS QUE INSERTAR UN NUMERO Y EL PROGRAMA TENIA QUE HACER LA MULTIPLICACION DE ESE NUMERO. USAMOS EL ‘FOR’, EL ‘WHILE’ Y EL ‘REPEAT’. EL NOMBRE DEL PROGRAMA ES TABLA DE MULTIPLICAR:

· FOR:
program Tabla;
uses crt;
var
z:integer;
num:integer;
begin
clrscr;
writeln('Bienvenido al programa de la tabla de multipicar');
writeln('Escribe un numero del 1 al 10');
readln(num);
if num<1
then
writeln('No has seguido las indicaciones')
else
if num>10
then
writeln('No has seguido las indicaciones')
else
for z:=1 to 10 do
begin
writeln(num*z);
end;
readkey;
end.


·REPEAT:
program Tabla;
uses crt;
var
z:integer;
num:integer;
begin
clrscr;
writeln('Introduce un numero del 1 al 10');
readln(num);
if num<0
then
writeln('No has seguido las indicaciones')
else
if num>10
then
writeln('No has seguido las indicaciones')
else
z:=1;
repeat
writeln(num*z);
z:=z+1;
until z>10;
readkey;
end.


·WHILE:
program Tabla;
uses crt;
var
z:integer;
num:integer;
begin
clrscr;
writeln('Escribe un numero del 1 al 10');
readln(num);
if num<0
then
writeln('No has seguido las indicaciones')
else
if num>10
then
writeln('No has seguido las indicaciones')
else
z:=1;
while z<=10 do
begin
writeln(num*z);
z:=z+1;
end;
readkey;
end.


EL PROGRAMA QUE VIENE A CONTINUACION NO SE PORQUE MOTIVO LO TENGO INACABADO. TRATABA SOBRE VECTORES Y CONSISITIA EN INTRODUCIR UN VECTOR DE CINCO ELEMENTOS Y CALCULAR LA SUMA TOTAL Y LA MEDIA DE LOS ELEMENTOS DEL VECTOR Y, EN LA SEGUNDA PARTE, INTRODUCIR DOS VECTORES DE TRES ELEMENTOS Y CALCULAR EL VECTOR SUMA, EL PRODUCTO ESCALAR, LOS MODULOS Y EL ANGULO QUE FORMAN. EL NOMBRE DEL PROGRAMA ES VECTORES:

program vectores;
uses crt;
var
opcion:real;
s,v1,v2,vT,pe,mv1,mv2,x,a:real;
v:array [...] of real;
opc:char;
i:real;

begin
clrscr;
repeat
writeln('Es ahora de elegir entre una de estas dos opciones propuestas 1/2');
if opc:1
then
begin
for i:1 to 5 do
begin
writeln('Introduce las componentes del vector');
readln(v[i]);
s:=v[1]+v[2]+v[3]+v[4]+v[5];
writeln('Has introducido el siguiente vector');
writeln('(',v[1]:0:2,',',v[2]:0:2,',',v[3]:0:2,',',v[4]:0:2,',',v[5]:0:2,')');
s:=0
for i:=1 to 5 do
s:=s+v[i];
p:=s/5;
end
else
begin
if opc:2
then
begin
for i:=1 to 3 do
begin
writeln('Introduce el vector 1');
readln(v1[i]);
end;
for 1 to 3 do
begin
writeln('Introduce el vector 2');
readln(v2[i]);
end;
writeln('El vector 1 introducido es');
writeln('(',v1[1]:0:2,',',v1[2],',',v1[3],')');
writeln('El vector 2 introducido es');
writeln('(',v2[1]:0:2,',',v2[2]:0:2,',',v2[3]:0:2,')');
for i:=1 to 3 do
writeln('El producto escalar de estos dos vectores es:');
pe:=+v1[i]*v2[i]
writeln('El modulo del vector 1 es:');
mv1:=sqrt(+sqr(v1[i]))
writeln('El modulo del vector 2 es:');
mv2:=sqrt(+sqr(v2[i]))
x:=pe/(mv1*mv2)
writeln('El angulo que forman el vector 1 y el vector 2 es:');
a:=arctan(sqrt(1-sqr(f))/f);
end;
end;


Y POR ULTIMO HICIMOS UN RETOQUE AL EJECICIO DE ADIVINAR, EXPLICADO UN POCO MAS ARRIBA, EN EL CUAL SOLO TENIAMOS UN NUMERO MAXIMO DE INTENTOS QUE HAY QUE FIJAR CON ANTERIORIDAD. EL NOMBRE DEL PROGRAMA ES ADIVINAR2:

program adivinar2;
uses crt;
var
int,i,num,a:integer;
nom:ansistring;
c:char;

Begin
clrscr;
write
('Escribe tu nombre: ');

readln (nom);
writeln('Bienvenido ',nom);
repeat
clrscr;
writeln
('A ver si adivinas en que numero del 1 al 10 estoy pensando');

repeat
write ('cuantos intentos necesitas (maximo 4): ');
readln (int);
if (int<1) or (int>4) then
writeln('he dicho maximo 4 intentos :)');
until (int>0) and (int<5);
i:=int;
randomize;
num:=random(9)+1;
repeat
write ('introduce un numero entero entre 1 y 10: ');
readln (a);
int:=int-1;
if a=num then
begin
writeln ('Enhorabuena el numero es ', a, ' y lo has conseguido en tu ', i-int, 'º intento.');
int:=0;
end
else
begin
if (a>0) and (a<11) then
writeln ('Has fallado, te quedan ', int,' intentos')
else
begin
writeln ('Error en el dominio de los datos de entrada, [1,10]');
writeln ('Te quedan ', int,' intentos');
end;
end;

until int=0;
if a<> num then
begin
writeln ('No lo conseguistes en ', i, ' intentos');
writeln ('La solución era: ', num);
end;
write ('Quieres volver a intentarlo (s/n)? ');
c:=readkey;
until c in ['n','N'];
End.

No hay comentarios:

Publicar un comentario