You are on page 1of 5

program project1;

USES

CRT;

type

vector=array [1..5] of byte;

function Primo (A:word):Boolean;

var

i,x:word;

begin

x:=0;

for i:=1 to (A div 2) do

If (A mod i =0) then

x:=x+1;

Primo:=x<=1;

end;

function Potencia(B:word;E:byte):Integer;

var

i:byte;

x:integer;

begin

x:=1;

for i:=1 to E do

x:=x*B;

Potencia:=x;

end;

procedure Crear_vector (N:word; var A:vector);


var

d:word;

r,i:byte;

begin

r:=N mod 10;

d:=N div 10;

for i:= 5 downto 1 do begin

A[i]:=r;

r:=d mod 10;

d:=d div 10;

end;

end;

function Suma_de_cubos (Z:word):boolean;

var

k:byte;

suma:word;

C:vector;

begin

suma:=0;

Crear_vector (Z,C);

for k:=1 to 5 do

suma:=suma+Potencia(C[k],3);

Suma_de_cubos:=suma=Z;

end;

function Suma_de_digitos (W:word):byte;

var
D:vector;

i,S:byte;

begin

S:=0;

Crear_vector (W,D);

for i:=1 to 5 do

S:=S+D[i];

Suma_de_digitos:=S;

end;

var

N,base,M,O,P:word;

exp,j:byte;

V:vector;

begin

writeln('Probando el subprograma "Primo"');

write('Introduce un valor: ');

readln(N);

if (Primo(N)) then writeln (N,' Es Primo') else writeln (N,' No es Primo');

writeln(' ');

readkey;

writeln('Probando el subprograma "Potencia"');

write('Introduce la base: ');

readln(base);
write('Introduce el exponente: ');

readln(exp);

writeln ('La potencia es igual a: ',Potencia(base,exp));

writeln(' ');

readkey;

writeln('Probando el subprograma "Crear_vector"');

write('Introduce un valor de 5 cifras menor o igual a 65535: ');

readln(M);

crear_vector(M,V);

for j:=1 to 5 do

write (V[j]:4);

writeln(' ');

readkey;

writeln ('Probando el subprograma "Suma_de_cubos"');

write('Introduce un valor de 5 cifras menor o igual a 65535: ');

readln(O);

if (Suma_de_cubos(O)) then writeln (O,' Si cumple') else writeln (O,' No cumple');

writeln(' ');

readkey;

writeln ('Probando el subprograma "Suma_de_digitos"');

write('Introduce un valor de 5 cifras menor o igual a 65535: ');

readln(P);

writeln(Suma_de_digitos(P));

writeln(' ');

readkey;
end.

You might also like