Are generally similar to algebraic expression in mathematics
Are generally similar to algebraic expression in mathematics. 15 X 15+7 X-Y 15+7*3/2 (X-Y)*2 In Pascal expressions, the constants and variables are operands while the special symbols are operators.
Operator + minus Operation addition subtraction/unary * multiplication / real division div integer division mod Quotient (Y div X) X modulo Expression Results of the real division, integer division and modulo operations on different values Arithmetic operators Result 11/4 2. 75 11 div 4 2 11 mod 4 3 2/5 0. 4 2 div 5 0 2 mod 5 2 Y Remainder (Y mod X) The integer division and modulo operations
Precedence level Operators Highest -(unary minus or negation High *, /, div, mod Low +, -
This is a way of assignment a value to a variable. The syntax of an assignment statement is <variable>: =<expression> Program assignmentdemo; 1 The variables A, B and C are declared with an integer data type. 2 A is assigned the value of 5. var A, B, C : integer; 1 begin A : =5; 2 B : =3; 3 C : = A+B; 4 3 B is assigned the value of 3. writeln(‘A=‘, A); 4 C is assigned the sum of A and B. writeln(‘C=‘, C) writeln(‘B=‘, B); end.
Pascal function Argument type Function operation Sqr(x) Integer or real Same as argument sqrt(x) integer or real return the square root of x (x>=0) integer or real returns the cosine of x (in radians), cos x integer or real returns the natural logarithm of x, ln x sin(x) cos(x) arctan(x) ln(x) exp(x) integer random(x) integer or real same as abs(x) argument round(x) real integer real trunc(x) integer Returns the square of x returns the sine of x (in radians), sin x returns the inverse tangent of x returns the value of raised to the power of x returns a random whole no. between 0 and x returns the absolute value of x, | x | returns the value of x rounded to the nearest integer returns the value of x truncated to a whole no.
Function Result round(100. 5) 101(rounded up) round(100. 4) 100(rounded down) round(-100. 5) -101(rounded down) round(-100. 4) -100(rounded up) Results of the rounding fruction on different values Function Results of the truncating function on different values Result trunc(100. 5) 100 trunc(100. 4) 100 trunc(-100. 5) -100 trunc(-100. 4) -100
- Slides: 12