Self Test on Operator Precedence
Write statements in Pascal which correctly express each of the following mathematical expressions.
             2                                2
 1. Z = X + Y                2.  Z = ( X + Y )

         A + B + E                        B
 3. Z = -----------          4.  Z = A + ---
           D + E                          C

         A + B                              B
 5. Z = -------              6.  Z = A + -------
           C                              D - C


             2                                2
 1. Z = X + Y                2.  Z = ( X + Y )

    Z := X + (Y * Y);            Z := (X + Y) * (X + Y);

         A + B + E                        B
 3. Z = -----------          4.  Z = A + ---
           D + E                          C

    Z := (A+B+E) / (D+E);        Z := A + (B / C);

         A + B                              B
 5. Z = -------              6.  Z = A + -------
           C                              D - C

    Z := (A + B) / C;            Z := A + ( B / ( D - C ) );



Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.
1