PROGRAM ComplexArithmetic(Output);

    { Program 7.1- Illustrate complex numbers operations. }

    CONST
        Increment = 4;
    TYPE
        Complex = RECORD
            Re, Im: Real
        END;
    VAR
        X, Y: Complex;
        Pair: Integer;
BEGIN
    X.Re := 2;      { initialize X}
    X.Im := 5;
    Y := X;         { initialize Y }

    FOR Pair := 1 TO 5 DO BEGIN
        WriteLn(Output, 'X = ', X.Re :5:1, X.Im :5:1, 'i');
        WriteLn(Output, 'Y = ', Y.Re :5:1, Y.Im :5:1, 'i');

        { X + Y }
        WriteLn(Output, 'Sum = ', X.Re + Y.Re :5:1, X.Im + Y.Im :5:1, 'i');

        { X * Y }
        WriteLn(Output, 'Product = ', X.Re * Y.Re - X.Im * Y.Im :5:1,
            X.Re * Y.Im + X.Im * Y.Re :5:1, 'i');

        WriteLn(Output);
        X.Re := X.Re + Increment;
        X.Im := X.Im - Increment
    END
END.
