Anda di halaman 1dari 22

ww.fisicaeingenieria.

es
EJERCICIO 1A.- ESCRIBIR UN PROGRAMA QUE CALCULE EL FACTORIAL DE UN NMERO DE MANERA DIRECTA:
program ejercicio1a; uses crt, math; var numero, i, factorial:integer; begin writeln ('Introducir el valor del numero:'); readln (numero); factorial:=1; for i:=1 to numero do begin factorial:=factorial*i; end; writeln ('El factorial de ', numero,' es ' , factorial); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 1B.- ESCRIBIR UN PROGRAMA QUE CALCULE EL FACTORIAL DE UN NMERO USANDO PROCEDIMIENTOS:
program ejercicio1b; uses crt, math; var numero, resultado:integer; function factorial (v:integer) :integer; var i:integer; begin factorial:=1; for i:=1 to v do factorial:=factorial*i; end; begin writeln ('Introducir el valor del numero:'); readln (numero); resultado:=factorial (numero); writeln ('El resultado es:', resultado); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 2A.- DETERMINAR SI UN NUMERO ES PRIMO DE MANERA DIRECTA:
program ejercicio2a; uses crt, math; var numero, i,j:integer; begin writeln ('introducir un numero entero:'); readln (numero); j:=0; for i:=2 to numero-2 do begin if (numero mod i)=0 then j:=1; end; if (j)=1 then begin writeln ('no primo'); readln; end; if (j)=0 then begin writeln ('El numero es primo');

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
readln; end; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 2B.- DETERMINAR SI UN NUMERO ES PRIMO O NO USANDO PROCEDIMIENTOS
program ejercicio2b; uses crt, math; var numero:integer; procedure primo(var num:integer); var i,j:integer; begin j:=0; for i:=2 to num-2 do begin if (num mod i)=0 then j:=1; end ; if (j)=1 then begin writeln ('El numero no es primo'); readln; end; if (j)=0 then begin writeln ('El numero es primo');

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
readln; end; end; begin writeln ('Introducir un numero'); readln (numero); primo (numero); end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 3A.- ESCRIBIR UN PROGRAMA QUE CALCULE LA VELOCIDAD DE UN CUERPO SABIENDO EL ESPACIO RECORRIDO Y EL TIEMPO DE MANERA DIRECTA
program ejercicio3a; uses crt, math; var espacio, tiempo, velocidad:real; begin writeln ('Escribir el espacio recorrido por el cuerpo:'); readln (espacio); writeln ('Escribir el tiempo empleado por el cuerpo:'); readln (tiempo); velocidad:=espacio/tiempo; writeln ('La velocidad del cuerpo es de ', velocidad:5:2, ' m/s'); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO3B.- ESCRIBIR UN PROGRAMA QUE ME PERMITA CALCULAR LA VELOCIDAD DE UN CUERPO SABIENDO EL ESPACIO Y EL TIEMPO USANDO PROCEDURE. program ejercicio3b; uses crt, math; var a,b:real; procedure velocidad (var espacio,tiempo:real); var vel:real; begin vel:=espacio/tiempo; writeln ('La velocidad del cuerpo es de ', vel:5:2, ' m/s'); readln; end; begin writeln ('Introducir el espacio recorrido por el cuerpo:'); readln (a); writeln ('Escribir el tiempo que tarda el cuerpo en recorrelo:'); readln (b); velocidad (a,b); end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 3C.- HACER UN PROGRAMA QUE ME PERMITA CALCULAR LA VELOCIDAD QUE LLEVA UN CUERPO SABIENDO EL ESPACIO Y EL TIEMPO Y USANDO FUNCTION. program ejercicio3c; uses crt, math; var a,b,c:real; function velocidad (var espacio,tiempo:real):real; begin velocidad:=espacio/tiempo; end; begin writeln ('Introducir el espacio recorrido por el cuerpo:'); readln (a); writeln ('Introducir el tiempo empleado por el cuerpo:'); readln (b); c:=velocidad (a,b); writeln ('La velocidad del cuerpo es de ', c:5:2,' m/s'); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 4.- ESCRIBIR UN PROGRAMA QUE USE PROCEDIMIENTOS Y QUE CALCULE EL REA Y EL VOLUMEN DE UN CILINDRO
program ejercicio4; uses crt,math; const pi=3.1416 ; var radio, altura, area, volumen:real; function area_cil (var a,b:real):real; begin area_cil:=2*pi*a*b; end; function volumen_cil (var a,b:real):real ; begin volumen_cil:=pi*a*a*b; end; begin writeln ('Introducir el radio del cilindro:') ; readln (radio); writeln ('Introducir la altura del cilindro:'); readln (altura); area:=area_cil (radio,altura); volumen:=volumen_cil (radio,altura); writeln ('El area del cilindro es de ',area:5:2);

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
writeln ('El volumen del cilindro es de ',volumen:5:2); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 5.- ESCRIBIR UN PROGRAMA QUE ME PREGUNTE SI TENGO UN CILINDRO O UNA ESFERA Y QUE CALCULE EL REA O EL VOLUMEN SEGN LO QUE PIDA EL USUARIO
program ejercicio5; uses crt, math; const pi=3.1416; var radio, altura, area_esf:real; opcion:integer; procedure area_cil (var a,b:real); var c:real; begin c:=2*pi*a*b; writeln ('El area del cilindro es ', c:5:2); end; function area_esfera (var a:real):real; begin area_esfera:=4*pi*a*a; end; begin writeln ('Introducir una opcion: 1.-Cilindro 2.-Esfera:'); readln (opcion); if (opcion)=1 then begin

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
writeln ('Introducir el radio del cilindro:'); readln (radio) ; writeln ('Introducir la altura del cilindro:'); readln (altura) ; area_cil(radio,altura); end else begin writeln ('Introducir el radio de la esfera:'); readln (radio); area_esf:=area_esfera(radio); writeln ('El area de la esfera es ',area_esf:5:2); end; readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 6.- ESCRIBIR UN PROGRAMA QUE CALCULE LAS SOLUCIONES DE UNA ECUACIN DE SEGUNDO GRADO Y QUE ME DIGA, EN EL CASO DE QUE NO TENGA SOLUCIONES, QUE LA ECUACIN NO TIENE SOLUCIN, USAR PROCEDIMIENTOS.
program ejercicio6; uses crt, math; var a, b, c:real; procedure soluciones (var x2, x, num:real); var discri,sol1,sol2:real; begin discri:=x*x-4*x2*num; if discri<0 then begin writeln ('La ecuacion no tiene solucion') end else begin sol1:=(-x+discri)/(2*x2); sol2:=(-x-discri)/(2*x2); writeln ('Las soluciones de la ecuacion son ',sol1:5:2,' y ',sol2:5:2); end; end;

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
begin writeln ('Introducir el termino a:'); readln (a); writeln ('Introducir el termino b:'); readln (b); writeln ('Introducir el termino c:'); readln (c); soluciones (a,b,c); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 7.- (PROPUESTO).- ESCRIBIR UN PROGRAMA QUE ME DIGA SI UN NMERO ES PAR O IMPAR, USANDO FUNCTION
program ejercicio7; uses crt, math; var numero,res: integer; function resultado (var num:integer):integer; begin if (num mod 2)=0 then resultado:=1 else resultado:=0; end; begin writeln ('Introducir un numero:'); readln (numero); res:=resultado (numero); if res=1 then begin writeln ('El numero es par'); end else begin

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
writeln ('El numero es impar'); end; readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 8.- (PROPUESTO).- ESCRIBIR UN PROGRAMA QUE ME DIGA SI UN NUMERO ES MAYOR O MENOR QUE 100 USANDO PROCEDIMIENTOS.
program ejercicio8; uses crt,math; var numero, resultado:integer; function res (var num:integer):integer; begin if num>100 then resultado:=1 else resultado:=0; end; begin writeln ('Introducir un numero'); readln (numero); res (numero); if resultado=1 then writeln ('El numero es mayor que 100') else writeln ('El numero es menor que 100'); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 9.- ESCRIBIR UN PROGRAMA QUE ME DE LA SUMA DESDE 0 HASTA UN NMERO DADO USANDO PROCEDIMIENTOS:
program ejercicio9; uses crt, math; var num, resultado:integer; function suma (var numero:integer):integer; var i:integer; begin suma:=0; for i:=1 to numero do begin suma:=suma+i; end ; end; begin writeln ('Introducir un valor numerico entero:'); readln (num); resultado:=suma (num); writeln ('El valor del sumatorio es:',resultado); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
EJERCICIO 10.- ESCRIBIR UN PROGRAMA QUE HAGA LA SUMA DE DOS VECTORES, SU PRODUCTO ESCALAR Y EL MDULO DE LOS VECTORES. EL PROGRAMA DEBE INCLUIR UN PROCEDIMIENTO QUE LEA EL VECTOR Y OTROS DOS (PROCEDURE O FUNCTION) QUE REALICE LAS OPERACIONES PERTINENTES.

program ejercicio10; uses crt, math; type vector=array [1..3] of real; var vector1, vector2,suma:vector; var modulo1,modulo2:real; procedure leer_vector (var v:vector); var i:integer; begin for i:=1 to 3 do begin writeln ('Escribir la componente ', i, ' del vector'); readln (v[i]); end; end ;

function suma_vectores (var v1,v2:vector):vector; var i:integer; begin

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
for i:=1 to 3 do suma_vectores [i]:=v1[i]+v2[i]; end ; function modulo (var v1:vector):real; var i:integer; begin modulo:=0; for i:=1 to 3 do modulo:=modulo+v1[i]*v1[i]; end; procedure escribir_vector (var v1:vector); var i:integer; begin for i:=1 to 3 do writeln ('La componente ',i,' del vector es ',v1[i]:5:2); end; begin leer_vector (vector1); leer_vector (vector2); suma:=suma_vectores (vector1,vector2); modulo1:=modulo (vector1); modulo2:=modulo (vector2);

Luis Muoz Mato

www.fisicaeingenieria.es

ww.fisicaeingenieria.es
escribir_vector (suma); writeln ('El modulo del primer vector es:', modulo1:5:2); writeln ('El modulo del segundo vector es:', modulo2:5:2); readln; end.

Luis Muoz Mato

www.fisicaeingenieria.es

Anda mungkin juga menyukai