SlideShare a Scribd company logo
1 of 16
Download to read offline
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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.

More Related Content

What's hot

Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perlsana mateen
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010Jordan Delacruz
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Algorithm and flowchart
Algorithm and flowchart Algorithm and flowchart
Algorithm and flowchart Shivam Sharma
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sqlÑirmal Tatiwal
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithmDHANIK VIKRANT
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptionsrehaniltifat
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Jayanshu Gundaniya
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
 

What's hot (20)

Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
Types of errors 2019
Types of errors 2019Types of errors 2019
Types of errors 2019
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010
 
Signal
SignalSignal
Signal
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Algorithm and flowchart
Algorithm and flowchart Algorithm and flowchart
Algorithm and flowchart
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Looping in C
Looping in CLooping in C
Looping in C
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptions
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Learn C
Learn CLearn C
Learn C
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 

Similar to Pascal for beginers tute

TOPIC-1-Introduction and Preliminaries.pdf
TOPIC-1-Introduction and Preliminaries.pdfTOPIC-1-Introduction and Preliminaries.pdf
TOPIC-1-Introduction and Preliminaries.pdfEjazAlam23
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer ProgrammingAllen de Castro
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c languageIndia
 
Software development slides
Software development slidesSoftware development slides
Software development slidesiarthur
 
Computer Programming Computer Programming
Computer Programming Computer ProgrammingComputer Programming Computer Programming
Computer Programming Computer Programmingarifhasan88
 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsOMWOMA JACKSON
 
Fundamental Programming Lect 2
Fundamental Programming Lect 2Fundamental Programming Lect 2
Fundamental Programming Lect 2Namrah Erum
 
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)Live Exam Helper
 
2. Algorithms Representations (C++).pptx
2. Algorithms Representations (C++).pptx2. Algorithms Representations (C++).pptx
2. Algorithms Representations (C++).pptxssuser4d77b2
 
Programming 1.pptx
Programming 1.pptxProgramming 1.pptx
Programming 1.pptxardrenful
 
Logic Development and Algorithm.
Logic Development and Algorithm.Logic Development and Algorithm.
Logic Development and Algorithm.NandiniSidana
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & ConditionsEbad ullah Qureshi
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfayush616992
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptReshuReshma8
 

Similar to Pascal for beginers tute (20)

01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
Week 1
Week 1Week 1
Week 1
 
TOPIC-1-Introduction and Preliminaries.pdf
TOPIC-1-Introduction and Preliminaries.pdfTOPIC-1-Introduction and Preliminaries.pdf
TOPIC-1-Introduction and Preliminaries.pdf
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
Software development slides
Software development slidesSoftware development slides
Software development slides
 
Computer Programming Computer Programming
Computer Programming Computer ProgrammingComputer Programming Computer Programming
Computer Programming Computer Programming
 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentals
 
Fundamental Programming Lect 2
Fundamental Programming Lect 2Fundamental Programming Lect 2
Fundamental Programming Lect 2
 
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
Python Exam (Questions with Solutions Done By Live Exam Helper Experts)
 
2. Algorithms Representations (C++).pptx
2. Algorithms Representations (C++).pptx2. Algorithms Representations (C++).pptx
2. Algorithms Representations (C++).pptx
 
Programming 1.pptx
Programming 1.pptxProgramming 1.pptx
Programming 1.pptx
 
Logic Development and Algorithm.
Logic Development and Algorithm.Logic Development and Algorithm.
Logic Development and Algorithm.
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
 
Excel
ExcelExcel
Excel
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.pptLecture1-Algorithms-and-Flowcharts-ppt.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
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.