Lesson 1
Lesson 1
Lesson 1
Basics
What is a program?
• A program is a set of instructions for
a computer, telling it what to do or
how to do it.
DO THIS
instructions computer
What is a programmer?
• A programmer is a person who
create, develop and write a
program.
Who can be programmer?
Anyone who have knowledge
in programming.
How to create a program?
• A program is created using different
programming languages.
• A program is created with different
stages. Sometimes call as programming cycle
Programming Cycle
Problem definition
Problem analysis
Algorithm
Development
Coding and
Debugging
Problem definition
• Specifies what we want the computer to do
• Optional • Madatory
(Hardware/Software) (Hardware/Software)
Ice breaker?
My friend gave me a code for my Java
language program. He wrote a code on
a piece of paper.
Is the code an algorithm or a program?
ALGORITHM
Characteristic of
Algorithm
Characteristics of Algorithm
• Input -Zero(0) to more
Flowchart
Lesson 3
What is a Flowchart?
• A flowchart is a graphical
representation of a sequence of
operations
• A flowchart contains symbols
describing how an algorithm or
program operates
What are the Symbols
used in Flowchart?
START
END
Initialization block
• Used for declaring / initializing variables
need to solve a certain process
• Declaration
- stating a variable name to be used
• Initialization
- to set (a starting value of a variable)
Initialization block
Declaration Initialization
Num1, Num1=5,
Num2 Num2=3
Process block
• The rectangle indicates a processing
block, for such things as calculations,
opening and closing files, and so forth
Sum=Num1+Num2
Input/Output block
• The parallelogram indicates input to
and output operations
Input Output
Get X Display X
Decision block
• The diamond indicates a decision
• It has one entrance and exactly two
exits from the block
• One exit is the action when the
resultant is TRUE and the other exit
is the action when resultant is FALSE
Decision block
T F
CONVENTION
Condition
TRUE FALSE
T F
Action when Action when YES NO
TRUE FALSE Y N
Condition
- a question or statement that gives
you an answer of T/F or Yes/No
Connectors
• The circle is used as a connection point
between two section of a flowchart that
are not adjacent or closely located to
each other Note:
• These connectors should
A be use as little as possible.
• The should only be use to
enhance readability. Overuse,
however, decreases readability
and produces a cluttered
A effect.
Logic Formulation
Flowchart and
Algorithm
Sample Problem
Lesson 3.1
Example 1
Create a flowchart display “Hello”
Algorithm Flowchart
1. Print “Hello” Start
Print
“Hello”
End
Example 2
Create a flowchart that display the sum of
2 and 5 Flowchart
Algorithm Start
1. Compute for the
sum of 2 and 5; Sum=0
Sum=2+5
2. Print Sum Sum=2+5
Print Sum
End
Example 3
Create a flowchart that ask the user to enter two number.
Compute and display their sum.
Algorithm Flowchart
Start
1. Enter 1st number
(num1) Sum=0;
2. Enter 2nd number Num1, num2
(num2)
Enter num1;
3. Compute for the Enter num2;
sum of num1 and
Sum=num1+num 2
num2;
Sum=num1 + num2 Print Sum
4. Print Sum
End
Example 4
Create a flowchart that ask the user’s age. Compute and
display his/her age five years from now.
Algorithm Flowchart
Start
1. Get user’s age
2. Compute age 5
age
years from now;
age= age + 5
Get age;
3. Print age
age= age + 5
Print Age
End
Try This
Create a flowchart that will compute for
the Average score of a student base on
three quizzes.
Algorithm
1. Get scores from the three quizzes (q1,q2,q3)
2. Compute for the average;
average=(q1+q2+q3)/3
3. Print average
Flowchart
Start
q1,q2,q3;
average=0
Get q1;
Get q2;
Get q3;
Average=(q1+q2+q3)/3
Print Average
End
Conditional Statement
• Statement that result to TRUE or FALSE
• More on Decision Block
Single Alternative Selection Structure
T F T F
Dual Alternative Selection Structure
• Performs two different things when
the condition is TRUE or FALSE
T F
Example 1
Draw flowchart that will ask the user to enter a character
indicating the user’s gender. If the user enters ‘M’ display
“You’re a male”
Flowchart
Algorithm Start
1. Get user’s gender
2. Ask if gender is ‘M’ gender
3. If yes; display
“You’re a male” Get gender;
T Is
F
Gender
==‘M’
Print “You’re a
male”
End
Example 2
Draw flowchart that will ask the user to enter a character
indicating the user’s gender. If the user enters ‘M’ display
“You’re a male”. If not assume that the user a female thus
display “You’re a female”.
Start
Algorithm
1. Get user’s gender gender
2. Decide for the gender
Get gender;
3. If ‘M’; display “You’re a male”
4. If not; display “You’re a T F
Is
female” Gender
==‘M’
Flowchart End
Example 3
Create a flowchart that will ask the user to enter two number.
Display “True” if the first number is greater than the second
number otherwise display “False” .
Algorithm
1. Enter two numbers Start
(num1,num2) num1,num2
2. Compare the two number is
num1>num2 Get num1;
Get num2;
3. If yes; display “True”
T F
Is
num1>num2
Flowchart End
Example 4 (Multiple Decision)
Create a flowchart that will ask the user to enter a number
from 1-3. If 1 is entered, print “Hello”; if 2 is entered, print
“Hi”; and if 3 is entered, then print “Bye”.
Algorithm
1. Enter a numbers (num)
2. Select the value of num
3. If 1; display “Hello”
4. If 2; display “Hi”
5. If 3; display “Bye”
Example 4 (Multiple Decision)
Flowchart
Start
num
Get num;
T
Is
Num==1 Print “Hello”
F
Is T
Num==2 Print “Hi” End
F
Is T
Num==3 Print “Bye”
Example 4 (Multiple Decision)
Create a flowchart that will ask the user to enter a number
from 1-3. If 1 is entered, print “Hello”; if 2 is entered, print
“Hi”; and if 3 is entered, then print “Bye”.
Otherwise, print “Invalid.”
Algorithm
1. Enter a numbers (num)
2. Select the value of num
3. If 1; display “Hello”
4. If 2; display “Hi”
5. If 3; display “Bye”
6. If not; display “Invalid”
Example 4 (Multiple Decision)
Flowchart
Start
num
Get num;
Is
T
Num==1 Print “Hello”
F
Is
T
Num==2 Print “Hi” End
F
Is
T
Num==3 Print “Bye”
Print “Invalid”