0% found this document useful (0 votes)
2 views2 pages

Pascal Program for Vector Operations

Uploaded by

Kuki Dog
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Pascal Program for Vector Operations

Uploaded by

Kuki Dog
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

program Hello;

USES crt;
CONST
MAX = 3;
TYPE
tVector = ARRAY[1..MAX] OF longInt;
VAR
vector :tVector;

PROCEDURE IniVector(VAR v: tVector);


VAR
i :byte;
BEGIN
FOR i := 1 TO MAX DO
v[i] := 0;
END; {IniVector}

PROCEDURE RellenarVector(VAR v: tVector);


VAR
i :byte;

BEGIN
FOR i := 1 TO MAX DO
BEGIN
WRITE(' INTRO DATO -->');
READLN(v[i]);
WRITELN;
READKEY;
END;
END; {RellenarVector}

PROCEDURE CalCuadradoVector(VAR v: tVector);


VAR
i :byte;
BEGIN
FOR i := 1 TO MAX DO
BEGIN
v[i] := sqr(v[i]);
END;
END; {CalCuadradoVector}

PROCEDURE MostrarVector(v: tVector);


VAR
i :byte;
BEGIN
FOR i := 1 TO MAX DO
BEGIN
WRITE(v[i], ' ');
END;
END; {MostrarVector}

PROCEDURE ComprobarSiprimos(v: tVector);


VAR
i :byte;

FUNCTION EsPrimo(n: longInt): boolean;


VAR
i :byte;
lim :longInt;
BEGIN
IF (n < 2) THEN
Exit(False);
IF ((n = 2) or (n = 3)) THEN
Exit(True);
IF (n mod 2 = 0) THEN
Exit(False);
lim := Trunc(sqrt(n));
FOR i := 3 TO lim DO
IF n mod i = 0 THEN
Exit(False);
Exit := true;
END; {EsPrimo}

BEGIN
FOR i := 0 TO MAX DO
EsPrimo(v[i]);
IF EsPrimo(v[i]) = True THEN
BEGIN
WRITE(' ES PRIMO', v[i]);
WRITELN;
END
ELSE
WRITELN(' NO HAY NINGUN PRIMO EN EL VECTOR');
END;

BEGIN {pp}
IniVector(vector);
RellenarVector(vector);
CalCuadradoVector(vector);
MostrarVector(vector);
ComprobarSiprimos(vector);

WRITELN();
WRITELN('FIN DE PROGRAMA ...PULSA UNA TECLA PARA CONTINUAR');
READKEY;

END. {PP}

You might also like