PF Lecture 2
PF Lecture 2
Programming
Fundamentals
Lecture # 03
Tuesday, September 21, 2020
FALL 2020
FAST – NUCES, Faisalabad Campus
Saqib Hayat
Algorithms and Problem
2
Solving Techniques
A flowchart
Shows logic of an algorithm
Emphasizes individual steps and their interconnections
Selection structure
Choose among alternative courses of action
Pseudocode example:
If student’s grade is greater than or equal to 50
Print “Passed”
If the condition is true
Print statement is executed and program continues to next
statement
If the condition is false
Print statement is ignored and program continues
Indenting makes programs easier to read
if ( grade >= 50 )
print "Passed";
A decision can be
made on any
expression.
true zero - false
grade >= 50 print “Passed”
nonzero - true
Example:
false 3 - 4 is true
if ( grade >= 50 )
Print "Passed";
else
Print "Failed";
false true
grade >= 50
print print
“Failed” “Passed”
Example
if ( grade >= 90 ) // 90 and above
Print "A";
else if ( grade >= 80 ) // 80-89
Print "B";
else if ( grade >= 70 ) // 70-79
Print << "C";
else if ( grade >= 60 ) // 60-69
Print "D";
else // less than 60
Print "F";
Compound statement
Set of statements within a pair of braces
if grade >= 60
Print "Passed"
else
Print "Failed";
Print "You must take this course again"
endif
Read one
number n1
Read second
number n2
Processing
Sum n1 + n2
Output
Display
Sum
End
CS118 - FALL 2020 Sep 03, 2018
Example 1
16
Pseudocode
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX VALUE1
else
MAX VALUE2
end if
Step 3: Print “The largest value is”, MAX
Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid
Average of 10 numbers
Write pseudocode and draw a flowchart to
determine the average of 10 numbers taken as input
from the user. The program must ask the user to
enter number by displaying a message.
After taking all 10 numbers average will be calculate
and then printed to the screen.
Avg = (n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + n10)/10