PF-Lec 02(Algorithm FlowChart Pseudocode)
PF-Lec 02(Algorithm FlowChart Pseudocode)
Fundamentals
CSC-131 – (3+1)
3
IPO
Chart
• It can be represented by the
following chart:
Input Processing Output
Processing Items:
Algorithm:
4
IPO
Chart
• The input section specifies all the inputs to the problem.
• All the symbols are then connected with arrows to show the flow of
the process.
10
Flow
Symbol
Chart
Name Meaning
11
Flow
Symbol
Chart
Name Meaning
Input-Output
Shows an input or output
(Parallelogram) instruction.
12
Flow
Symbol
Chart
Name Meaning
13
Flow
Symbol
Chart
Name Meaning
14
Problem
Examples
IPO Charts, Algorithms and Flow
Charts
15
Problem 01: Area of
rectangle
16
Problem 01 - IPO Chart and
Algorithm
Input Processing Output
• Width of Processing Items: • Area of
rectangle area = width * height rectangle
• Height of
rectangle Algorithm:
Step 01: Start
Step 02: Input width, height
Step 03: area = width* height
Step 04: Print area
Step 05: End
17
Problem 01 – Flow
Chart
18
Problem 02 : Average of three
numbers
19
Problem 02 - IPO Chart and
Algorithm
20
Problem 02 – Flow
Chart
21
Problem 03 : Temperature scale
conversion
22
Problem 03 - IPO Chart and
Algorithm
Input Processing Output
• Temperature Processing Items: • Temperature in
in F = C * 1.8 Fahrenheit
Celsius + 32 K = C • Temperature
+ 273.15 in Kelvin
Algorithm:
Step 01: Start
Step 02: Input C
Step 03: F= (C * 1.8) + 32
Step 04: K= C + 273.15
Step 05: Print F and K
Step 06: End
23
Problem 03 – Flow
Chart
24
Problem 04 : Area and circumference of
a circle
25
Problem 04 - IPO Chart and
Algorithm
Input Processing Output
• Radius of Processing Items: • Area of circle
circle area = π * radius^2 • Circumferenc
circumference = 2 * π * e of circle
radius
Algorithm:
Step 01: Start
Step 02: Input radius
Step 03: set PI = 3.1415
Step 04: area = PI * radius^2
Step 05: circumference = 2 * PI * radius
Step 06: Print area , circumference
Step 07: End
26
Problem 04 – Flow
Chart
27
Problem 05 : Buntty, Bubbly and Building
𝐷𝑖𝑠_𝐵𝑢𝑛_𝐵𝑢𝑏2 +
Step 02: Input Dis_Bun_Bub, Height_Bui
𝐻𝑒𝑖𝑔ℎ𝑡_𝐵𝑢𝑖2
Step 03: Dis_Bub_Bui =
29
Problem 05 - IPO Chart and
Algorithm
Input Processing Output
Step 04: Print Dis_Bub_Bui
Step 05: End
30
Problem 05 – Flow
Chart
31
Problem 06 : Notes and Coins
𝑠𝑎𝑙𝑎𝑟𝑦/𝑛𝑜𝑡𝑒_𝑎𝑚𝑜𝑢𝑛𝑡
amoun No of notes = • Number of notes of 1000
t • Number of notes of 500
𝑠𝑎𝑙𝑎𝑟𝑦/𝑐𝑜𝑖𝑛_𝑎𝑚𝑜𝑢𝑛𝑡
No of coins = • Number of notes of 100
• Number of notes of 50
• Number of notes of 20
Algorithm: • Number of notes of 10
Step 01: Start • Number of coins of 5
Step 02: Input salary • Number of coins of 2
𝑠𝑎𝑙𝑎𝑟𝑦/5000
Step 03: notes_5000 = • Number of coins of 1
35
Problem 06 – Flow
Chart
36
Problem 06 – Flow
Chart
Zoom-In to have a
clear view
37
Problem 07 : Even or odd
number
38
Problem 07 - IPO Chart and
Algorithm
Input Processing Output
• Integer Processing Items: • Number is
number If (number MOD 2) = 0 then it odd or even
is even If (number MOD 2) ≠
0 then it is odd
Algorithm:
Step 01: Start
Step 02: Input number from the user
Step 03: if (number MOD 2) == 0 then GOTO Step
04
else GOTO Step 05
Step 04: Print “Number is even” GOTO Step 06
Step 05: Print “Number is odd”
Step 06: End 39
Problem 07 – Flow
Chart
40
Problem 08 : Positive
numbers
41
Problem 08 - IPO Chart and
Algorithm
Input Processing Output
• Integer Processing Items: • Number if
number If (number > 0) then it is positive it
is positive
Algorithm:
Step 01: Start
Step 02: Input number
Step 03: if (number > 0) then Print number
Step 04: End
42
Problem 08 – Flow
Chart
43
Problem 09 : Largest
number
Problem Statement: Write a program that receives three unique
integer numbers from the user and displays the largest number.
44
Problem 09 - IPO Chart and
Algorithm
Input Processing Output
• First number Processing Items: • Large
• Second If (num1> num2 and num1 > num3) then num1 st
number is largest If (num2> num1 and num2 > num3) numb
• Third number then num2 is largest If (num3> num1 and er
num3 > num2) then num3 is largest
Algorithm:
Step 01: Start
Step 02: Input num1, num2 and num3 from the user
Step 03: if (num1> num2 and num1 > num3) then GOTO
Step 05
Step 04: if (num2> num1 and num2 > num3) then
GOTO Step 06 else GOTO Step 07
45
Problem 09 - IPO Chart and
Algorithm
Input Processing Output
Step 05: Print num1 GOTO
Step 08 Step 06: Print num2
GOTO Step 08 Step 07: Print
num3
Step 08: End
46
Problem 09 – Flow
Chart
47
Problem 10 : Marks
sheet
48
Problem 10 - IPO Chart and
Algorithm
Input Processing Output
• Marks of Processing Items: • Percenta
first Percentage = (Obtained marks/Total ge of
subject marks)*100 If(Percentage >= 85) grade marks
• Marks of = A+ • Grade
second If(Percentage >= 80 and Percentage <= 84) obtained
subject grade = A If(Percentage >= 75 and
• Marks of Percentage <= 79) grade = B+
third If(Percentage >= 70 and Percentage <= 74)
subject grade = B If(Percentage >= 65 and
• Marks of Percentage <= 69) grade = C+
fourth If(Percentage >= 60 and Percentage <= 64)
subject grade = C If(Percentage >= 55 and
• Marks of fifth Percentage <= 59) grade = D+
subject If(Percentage >= 50 and Percentage <= 54)
grade = D If(Percentage <= 49) grade = F49
Problem 10 - IPO Chart and
Algorithm
Input Processing Output
Algorithm:
Step 01: Start
Step 02: Input marks of subjects sub1, sub2, sub3, sub4 and
sub5
from the user
Step 03: Calculate percentage as :
per = ((sub1 + sub2 + sub3 + sub4 + sub5)/500)*100
Step 04: If (per>=85) then grade=“A+” GOTO Step 10
Step 05: If (per>=80 and per<=84) then grade=“A” GOTO
Step 13 Step 06: If (per>=75 and per<=79) then grade=“B+”
GOTO Step 13 Step 07: If (per>=70 and per<=74) then
grade=“B” GOTO Step 13 Step 08: If (per>=65 and per<=69)
then grade=“C+” GOTO Step 13 Step 09: If (per>=60 and
per<=64) then grade=“C” GOTO Step 13 Step 10: If
(per>=55 and per<=59) then grade=“D+” GOTO Step 13 50Step
11: If (per>=50 and per<=54) then grade=“D” GOTO Step 13
Problem 10 - IPO Chart and
Algorithm
Input Processing Output
Step 12: If (per<=49) then grade=“F”
Step 13: Print per, grade
Step 14: End
51
Problem 10 – Flow
Chart
52
Problem 10 – Flow
Chart
Zoom-In to have a
clear view
53
Problem 11 : First 10 integer
numbers
54
Problem 11 - IPO Chart and
Algorithm
Input Processing Output
Processing Items: • First
1, 2, 3, . . . , 10 10
integer
Algorithm:
Step 01: Start numbe
Step 02: Set i = 1 rs
Step 03: For i = 1 to 10
Step 04: Print i
Step 05: Set i =
i+1
Step 06: Next I
Step 07: End
55
Problem 11 – Flow
Chart
56
Problem 12 : Sum of first N integer
numbers
57
Problem 12 - IPO Chart and
Algorithm
Input Processing Output
• Number N Processing Items: • Sum of first
Sum = 1 + 2 + 3 + , . . . , + N N integers
Algorithm:
Step 01: Start
Step 02: Input N from the
user Step 03: Set i = 1,
sum = 0
Step 04: Repeat Step 05 to Step 06 while i <=N
Step 05: Set sum = sum + i
Step 06: Set i =
i + 1 Step 07:
Print sum Step
08: End
58
Problem 12 – Flow
Chart
59
Problem 13 : First N even
numbers
60
Problem 13 - IPO Chart and
Algorithm
Input Processing Output
• Number N Processing Items: • First N
2N even
number
Algorithm:
Step 01: Start
Step 02: Input N from the
user Step 03: Set i = 1
Step 04: Repeat Step 05 to Step 06 while i <=N
Step 05: Print
2*i Step 06: Set
i = i + 1 Step 07:
End
61
Problem 13 – Flow
Chart
62
Problem 14 : First N multiples of
5
63
Problem 14 - IPO Chart and
Algorithm
Input Processing Output
• Number N Processing Items: • First N multiples of
5, 10, 15, 20, 25, . . . , N*5 5
Algorithm:
Step 01: Start
Step 02: Input N from the
user Step 03: Set i = 1
Step 04: Repeat Step 05 to Step 06 while i <=N
Step 05: Print i
* 5 Step 06: Set
i = i + 1 Step 07:
End
64
Problem 14 - IPO Chart and
Algorithm
Input Processing Output
• Number N Processing Items: • First N multiples of
5, 10, 15, 20, 25, . . . , N*5 5
Algorithm:
Step 01: Start
Step 02: Input N from the
user Step 03: Set i = 5
Step 04: Repeat Step 05 to Step 06 while i <=N*5
Step 05: Print i
Step 06: Set i =
i + 5 Step 07:
End
65
Problem 14 – Flow
Chart
66
Problem 14 – Flow
Chart
67
Problem 15 : Factorial of a
number
68
Problem 15 - IPO Chart and
Algorithm
Input Processing Output
• Number N Processing Items: • Factorial of N
N! = N * (N-1) * (N-2) * , . . . , * 1
Algorithm:
Step 01: Start
Step 02: Input N from the
user Step 03: Set i = N ,
factorial = 1
Step 04: Repeat Step 05 to Step 06 while i >1
Step 05: Set factorial = factorial * i
Step 06: Set i = i - 1
Step 07: Print
factorial Step 08:
End
69
Problem 15 – Flow
Chart
70
Problem 16 : Prime or composite
number
71
Problem 16 - IPO Chart and
Algorithm
Input Processing Output
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = 2 , isPrime = true
Step 04: Repeat Step 05 to Step 06 while i < N
Step 05: if (N MOD i) = 0 then isPrime = false GOTO Step
07
Step 06: Set i = i + 1
Step 07: if isPrime = true GOTO Step 08 else GOTO Step 72
09
Problem 16 - IPO Chart and
Algorithm
Input Processing Output
73
Problem 16 – Flow
Chart
74
End of lecture
End of lecture