TALENTS FOR DEVELOPMENT - Petrovietnam UniversityChapter 1: AlgorithmLecturer: Trần Ngọc Hiệp, MSc.Email: hieptn@pvu.edu.vnMobile: 0901 25 2468... Foundations of Engineering II- PVUTALEN
Trang 1TALENTS FOR DEVELOPMENT - Petrovietnam University
Chapter 1: Algorithm
Lecturer: Trần Ngọc Hiệp, MSc.Email: hieptn@pvu.edu.vnMobile: 0901 25 2468
Trang 2Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
Trang 3Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
Trang 4Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
1.3 Algorithm Designing tools
Algorithm Designing tools:
1 pseudo codes2 flowcharts
1.3 Algorithm Designing tools
1 Pseudo codes
• Pseudo code is an artificial and informal language that helps the programmers to develop algorithm in the text format.
7
Trang 5Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
1.3 Algorithm Designing tools
2 flowcharts
• Flowchart is the diagrammatic way of representing, the steps to be followed for solving the given problem.
1.3 Algorithm Designing tools
9
Trang 6Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
1.3 Algorithm Designing toolsExample 1
• Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing The final grade is calculated as the average of four marks.
- Input a set of 4 marks
- Calculate their average by summing and dividing by 4- if average is below 50
Print “FAIL”
Print “PASS”
11
Trang 7Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
1.3 Algorithm Designing toolsFlowchart: Example 1
Step 1: Input Q1,Q2,Q3,Q4
Step 2: GRADE (Q1+Q2+Q3+Q4)/4 Step 3: if (GRADE <50) then
Print “FAIL”else
Print “PASS”end if
1.3 Algorithm Designing toolsPseudo codes: Example 2
- Input the length in feet (Lft)
- Calculate the length in cm (Lcm) by multiplying LFT with 30
- Print length in cm (LCM)
13
Trang 8Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
1.3 Algorithm Designing toolsFlowchart: Example 2
Step 1: Input Lft
Step 2: Lcm Lft x 30 Step 3: Print Lcm
Lcm Lft x 30
15
Trang 9Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
1.3 Algorithm Designing toolsFlowchart: Example 3
Trang 10Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
7.5 Summary
1• What is an algorithm?2• Characteristic of algorithm3• How to writing algorithm
1.4 QUIZ
19
Trang 11Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
Home Work
across a river He has a rowboat, and it can only carry him and one other thing If the fox and the chicken are left together, the fox will eat the chicken If the chicken and the corn is left together, the chicken will eat the corn How does the man do it? Solve the problem and make a flow chart with solution.
21
Trang 12Trần Ngọc Hiệp, MSc Foundations of Engineering II- PVUTALENTS FOR DEVELOPMENT - Petrovietnam University
23