Introduction To Pascal Programming Language: Input / Output
Introduction To Pascal Programming Language: Input / Output
Introduction to Pascal
Programming Language
Input / output
Learning Outcomes
Upon completion of this lecture learners will
be able to:
Apply input and output command in Pascal
Write a complete sequential Pascal program that
involves input and output format.
Page 2 of 12
Input
In pseudocode, we get input from user by
having an instruction like
2.0 get num
In flowchart, we get input from user by
having an instruction like
Get num
Page 3 of 12
..Input
In Pascal, we use read() or readln() to get
input from user
Syntax
Example
read (num);
read (num1, num2);
Syntax
Example
readln (num);
readln (num1, num2);
Page 4 of 12
..Input
read() and readln() take input from
keyboard and store the input in the specified
variable
Example
100
100
var num1,
num1
num2 : integer;
200
200
num2
Page 5 of 12
..Input
read() vs. readln()
read() treats inputs a stream of data until
end of line character found (press enter).
readln() will skip into the next line after a
number of inputs entered.
Example?
Page 6 of 12
Output
In pseudocode, we display output to user by
having an instruction like
2.0 display num
In flowchart, we display output to user by
having an instruction like
display num
Page 7 of 12
..Output
In Pascal, we use write() or writeln() to
display output to user
write() displays the output and the next output
continues in the same line.
Syntax
write(<variable list>);
write(constant string);
Write(constant string,variable);
Example
write(num);
write(Please enter a number --> );
write(Number one is , num1);
Write(x is, x, & y is , y);
Page 8 of 12
..Output
writeln() displays the output and jump to the
next line.
The next output continues in the next line.
Syntax
writeln(<variable list>);
writeln(constant string);
Writeln(constant string,variable);
Example
writeln(num);
writeln(Enter a number --> );
writeln(Number one is , num1);
Writeln(x is, x, & y is , y);
Page 9 of 12
Example
Page 10 of 12
Formatting Output
num = 45.9053
Writeln(num);
#4.590530000000000E+001
Writeln(num:5);
#4.6E+001
Writeln(num:5:2); 45.91
Writeln(num:7:3); #45.905
Writeln(num:6:5); 45.90530
Writeln(num:6:2, num:7:3);
#45.91#45.905
Page 11 of 12
Formatting Output
Page 12 of 12