This document contains a lecture on Pascal programming presented by Anutthara Senanayake. It introduces Pascal concepts like variables, data types, operators, control structures like if/else, for loops and functions. It provides 24 exercises for students to write Pascal programs that demonstrate understanding of these basic concepts through problems like calculating sums, finding maximum values, grading systems and more. The document aims to teach the fundamentals of Pascal programming through examples and hands-on practice exercises.
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Pascal for beginers tute
1. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
1
Write programs to solve problems – Pascal Programming
Session – 01
Conducted By:
Department of Information Technology,
SIBA Campus,
Pallekale,
Kundasale
2. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
2
Pascal Overview
Pascal is a general purpose high level language that was originally developed by Nikaus
Wirth in the early 1970s.
Easy to learn
Structured language
It produces transparent, efficient and reliable programs
It can be compiled on a variety of computer platforms
Environment
Turbo Pascal: Provides an IDE and compiler for running Pascal programs on DOS,
Windows and Macintosh.
Pascal Language
Identifiers
Identifiers are names that allow you to reference stored values, such as variables and
constants.
Exercise 01
Select the valid identifiers from the given list.
1. Myname
2. @me2
3. me2
Note
For identifiers:-
Cannot use reserved words. Eg:- begin, end etc.
Must start with a letter
After the first letter can use numbers and the underscore ( _ ) sign. Eg:- student_name
Cannot keep spaces
Non case sensitive
Cannot use symbols other than the underscore
As a good programmer it is good to use meaningful names
3. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
3
4. saman
5. my-add
6. my_add
7. $sea_u
Reserved Words
The statements in Pascal are designed with some specific Pascal words, which are called
the reserved words. For example, the words, program, input, output, var, real, begin,
readline, writeline and end are all reserved words. Following is a list of reserved words
available in Pascal.
Data Types
In computer science and computer programming, a data type or simply type is a
classification identifying one of various types of data, such as real, integer or Boolean.
4. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
4
Variables
A variable is a storage location paired with an associate identifier which contains some
known or unknown quantity of information referred to as a value. In Pascal, variable can be
defined by using the reserved word var.
var myname : string
Const
A const is a keyword applied to a data type that indicates that the data is constant (does not
vary).
Const pi=22/7;
Operators
An operator is a symbol that tells the compiler to perform specific mathematical or logical
functions.
Three types of operators:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
Note
The value of a constant cannot be changed during the run time like a variable
5. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
5
Arithmetic Operators
Operator Usage Expression
+ Add 6+3
- Minus 7-5
* Multiplication 2*5
/ Division 10/4
DIV Division 20 DIV 6
MOD Modulus 20 MOD 6
Relational Operators
Operator Usage Expression Result
> Greater than 7>3 True
>= Greater than or equal 8>=8 True
< Smaller than 3<2 False
<= Smaller than or equal 4<=6 True
= Equal 3=1 False
<> Not equal 2<>5 True
Logical Operators
AND
OR
NOT
Pascal Example
Pascal Program
6. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
6
Program Structure
Exercise 02
Write a Pascal program to calculate the sum of two integer numbers.
Flow Chart
Start
Set sum=0
Input number1,
number2
Sum=number1+number2
Display sum
Stop
Pseudo Code
Begin
Set sum=0
Input number1, number2
sum=number1+number2
Print sum
End
Pascal Program
7. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
7
Control Structures
1. IF…THEN…ENDIF
Exercise 03
Write a Pascal program to print the entered, number if it is only a positive number.
Exercise 04
Write a Pascal program to print “Pass” if the mark is greater than 50.
Flow Chart
Start
Input number
If
number
>0
Print number
Stop
Yes
No
Pseudo Code
Begin
Input number
IF number>0
THEN
Print number
ENDIF
End
Pascal Program
8. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
8
2. IF….THEN….ELSE…..ENDIF
Exercise 05
Write a Pascal program to find the maximum number out of two given numbers.
Flow Chart
Start
Input num1, num2
If
num1>num2
Print num1 Print num2
Stop
Yes No
Pseudo Code
Begin
Input num1,num2
IF num1>num2
THEN
Print num1
ELSE
Print num2
ENDIF
End
Pascal Program
9. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
9
Exercise 06
Write a Pascal program to print “Adult” if the given age is greater than 18 otherwise prints
“Child”.
3. Nested IF
Exercise 07
Write a Pascal program to print the correct grade for the given mark. (mark >= 75 =>A, mark
>=65=> B, mark >=50 =>C, mark =>35=>S, else F)
Note
When using the if else statements, make sure to put the semicolon to the last statement
Flow Chart
Start
Input mark
If mark
=>75
If mark
=>65
If mark
=>50
If mark
=>35
Set grade
Grade=A Grade=B Grade=C Grade=S
Grade=F
Print grade
Stop
No No No No
Yes
Yes
Yes Yes
10. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
10
Exercise 08
Write a Pascal program to display the day of the week when the day number is provided.
Eg:- 3 – Wednesday
4. CASE statements
Exercise 09
Write a Pascal program to print the grade according to the criteria for the given mark.
0-34 => F , 35 – 49 =>S , 50 – 64 =>C, 65 – 74 => B, 75 – 100 =>A
Pseudo Code
Begin
Set grade
Input mark
IF mark=>75 THEN
grade=A
ELSE IF mark =>65 THEN
grade = B
ELSE IF mark=>50 THEN
grade = C
ELSE IF mark => 35 THEN
grade = S
ELSE
grade = F
ENDIF
ENDIF
ENDIF
ENDIF
Display grade
End
Pascal Program
11. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
11
Flow Chart
Start
Input mark
mark
Set grade
grade=W grade=S grade=C grade=B grade=A
Display grade Display Invalid
Mark
Stop
0-34
35-49 50-64 65-74 75-100
Other
Pascal Program
12. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
12
5. FOR - DO
Exercise 10
Write a Pascal program to print numbers starting from 10 to 1.
Exercise 11
Write a Pascal program to calculate the sum and the average of given 10 numbers.
Pascal Program
Pascal Program
13. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
13
6. WHILE DO
Exercise 12
Develop a computer based solution to receive a set of positive numbers or 0 from user and
display the total value. Data input will stop when a negative value is entered.
Flow Chart Pseudo Code
Pascal Program
14. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
14
7. REPEAT UNTIL
Exercise 13
Write a Pascal program to print the word “Pascal” 5 times.
8. Nested Control Structures
Exercise 14
Write a Pascal program to make a number series according to the ascending or descending
order.
Pascal Program
Pascal Program
15. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
15
Exercise 15
Write a Pascal program to input numbers and calculate the count of odd numbers and the
count of even numbers.
Exercise 16
Write a program to print the following words on the console screen.
Hello. How are you?
I'm just fine.
Exercise 17
Write a program to calculate the gross pay for a worker named FRED given that FRED
worked 40 hours at $2.90 per hour.
Exercise 18
Pascal Program
16. Anutthara Senanayake - Lecturer
Sri Lanka International Buddhist Academy
16
Write a program to input two numbers and calculate the sum and the average of them.
Exercise 19
Construct a program to find the maximum value of three user input numbers.
Exercise 20
Write a program to receive month number and output the number of days that month has.
Do not consider a leap year first but help students modify the program to consider that also.
(Hint: 2=> 28 days, 1,3,5,7,8,10,12 =>31 days, 4,6,9,11 => 30 days)
Exercise 21
Write a program to calculate the sum of numbers starting from 1 to 10. (Use WHILE-DO)
Exercise 22
Write a Pascal program to find the sum of even numbers starting from 2 to 20.
Exercise 23
Write a PASCAL program to calculate the area and circumstance of circle by inputting the
radius of the circle.
Exercise 24
Problem: Develop a computer based solution to receive a set of positive numbers or 0 from
user and display the maximum value. Input of negative value will stop the input of numbers.