3.1 Assignment Operator
Used to give value to a variable.
example:
x: = 1 + 2;
a: = a +1;
3.2 Arithmetic Operators
+
Used to do the sums.
example: a + b
-
Used to make cuts.
example: x - 1
*
Used to perform multiplication.
example: a * b
/
Used to make distributions.
example: 7/3
div
For integer division.
example:
10 div 5, will produce 2
10 div 3, will produce 3
mod
Used to calculate the remaining share.
example:
10 mod 5, will result in 0
10 mod 3, will produce 1
Showing posts with label Pascal. Show all posts
Showing posts with label Pascal. Show all posts
Thursday, May 24, 2012
Wednesday, March 21, 2012
2. Pascal statements
clrscr
Used to clean / clear the screen.
write / writeln
Used to display text or value of a variable on the screen.Difference between the write writeln is at the cursor position after the statement is executed. On write, the cursor will be behind the text, while the writeln, the cursor will be on the next line.
example:
write ('example');
writeln ('example');
writeln (a), (showing the contents of a variable)
write ('Hello', a);
read / readln
Used to read and enter a value that is inputted through the keyboard into a variable.
example:
readln (a), (insert the data inputted into the variable a)
readln; (waiting for the user presses the enter button before proceeding to the next statement)
Used to clean / clear the screen.
write / writeln
Used to display text or value of a variable on the screen.Difference between the write writeln is at the cursor position after the statement is executed. On write, the cursor will be behind the text, while the writeln, the cursor will be on the next line.
example:
write ('example');
writeln ('example');
writeln (a), (showing the contents of a variable)
write ('Hello', a);
read / readln
Used to read and enter a value that is inputted through the keyboard into a variable.
example:
readln (a), (insert the data inputted into the variable a)
readln; (waiting for the user presses the enter button before proceeding to the next statement)
Thursday, January 5, 2012
A. Program Structure
Here is a sample source code of a Pascal program:
sample program;
uses crt;
var
a: string;
begin
clrscr;
write ('Enter your name:');
readln (a);
writeln ('Hello', a);
readln;
end.
program
Contains the name / title of the program, in this case the 'example'.
uses
Contains a list of units to be used in the program, namely 'crt'. Unit is a separate program module and used to store related processes/function. As in the example, 'uses crt' means the program uses a unit called 'crt', which contains a collection of routines (procedures and functions) to control PC. If the program uses more than one unit, then each unit separated by commas (example: uses crt, dos ;).
var (declaration)
Contains a list of variables to be used in the program (in this example is 'a') and its data type (string), or can be called with the variable declaration. In addition to the variables, other declarations needed a program include:
Examples of constant and variable declarations:
const
n = 100;
var
a: integer;
begin-end
Contains statements that will run the program. Examples of statements are clrscr, writeln, readln, etc.. These statements should be in the begin-end block.
sample program;
uses crt;
var
a: string;
begin
clrscr;
write ('Enter your name:');
readln (a);
writeln ('Hello', a);
readln;
end.
program
Contains the name / title of the program, in this case the 'example'.
uses
Contains a list of units to be used in the program, namely 'crt'. Unit is a separate program module and used to store related processes/function. As in the example, 'uses crt' means the program uses a unit called 'crt', which contains a collection of routines (procedures and functions) to control PC. If the program uses more than one unit, then each unit separated by commas (example: uses crt, dos ;).
var (declaration)
Contains a list of variables to be used in the program (in this example is 'a') and its data type (string), or can be called with the variable declaration. In addition to the variables, other declarations needed a program include:
- Declaration of data types
- Declaration of constants
- Variable declaration
- Declaration procedure
- Function declaration
- Label declaration
Examples of constant and variable declarations:
const
n = 100;
var
a: integer;
begin-end
Contains statements that will run the program. Examples of statements are clrscr, writeln, readln, etc.. These statements should be in the begin-end block.
Subscribe to:
Posts (Atom)