Вы находитесь на странице: 1из 2

{Primer Ejemplo}

PROGRAM Ejemplo;
VAR a, b: INTEGER;

{globales}

PROCEDURE proc1 (VAR x: INTEGER);


VAR b: INTEGER;
BEGIN
b:= 3;
x:= b * 2 + a
END;
{fin de proc1}
PROCEDURE proc2 (d: INTEGER);
VAR
u: INTEGER;
v: BOOLEAN;
FUNCTION fun (x: INTEGER): BOOLEAN;
VAR a: INTEGER;
BEGIN
a:= 2;
return (u MOD a) = b
END;
{fin de fun}
BEGIN
{proc2}
u:= a + d;
v:= fun (u)
END;
{fin de proc2}
BEGIN

END.

{principal}
a:= 1;
proc1 (a);
proc2 (a);
fun (b)
{fin de principal}

/*Segundo Ejemplo*/
int a, b;

/*globales*/

void proc1 (int *x)


{
int b;
b = 3;
*x = b * 2 + a;
}
boolean fun (int x)
{
int a;
a = 2;
return (u % a) == b;
}
void proc2 (int
{
int u;
boolean
u = a +
v = fun
}
void main ()
{

d)
v;
d;
(u);

a = 1;
proc1 (&a);
proc2 (&a);
fun (b);

{Segundo parcial, junio de 2005}


...
Procedure magic
Integer: d, x, y, z
{variables locales del procedimiento
magic}
Integer: Function clculo (Integer: x, y)
{x,y: parmetros
por referencia}
Integer: a
{variable local de la funcin}
Procedure operacin (Integer: x, y)
{x,y: parmetros
por referencia}
Begin operacin
a:= x * d + y
z:= y * d + x
End operacin
Begin clculo
If (x = y) Then magic
Else
Begin
d:= 10
operacin (x, y)
a:= a z
x:= a / d
{divisin con resultado entero
truncado (ejemplo: 7/4=1)}
y:= a x * d
operacin (y, x)
Return z + a
End
End clculo
Begin magic
Write Escribe dos dgitos distintos:
{impresin por
pantalla}
x:= ReadDigit {lectura de un dgito por el teclado}
y:= ReadDigit
Write Resultado:
If (x > y) Then Write clculo (x, y)
Else Write clculo (y, x)
End magic
..

Вам также может понравиться