0% found this document useful (0 votes)
131 views

Lesson 1

Here is the flowchart for the given algorithm: [FLOWCHART] Start num1, num2 Get num1 Get num2 Is num1 > num2? T F Print "True" Print "False" End
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Lesson 1

Here is the flowchart for the given algorithm: [FLOWCHART] Start num1, num2 Get num1 Get num2 Is num1 > num2? T F Print "True" Print "False" End
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Programming

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

“What do I want the computer to do?”


Problem analysis
• Breaking down the problem into smaller sub
problems

• “What programming language


should I use?”

• “Do I need other hardware or


software?”
Algorithm development
• strategy on how to do the task

Maybe express in:


➢ Human Language
➢ Graphical representation(flowchart)
➢ pseudocode

Coding and Debugging


• the process of moving errors
Introduction to
Algorithm
Lesson 2
What is an Algorithm?
• A step by step procedure in solving
a problem
• Finite set of instructions that specify
a sequence of operations to be
carried out
“What is a program?”
“Isn’t a program also an instruction?”
What is the
Difference Between
Algorithm and
Program
Algorithm VS Program
• Domain Knowledge • Programmer

• Any language • Programming Language

• 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

• Output -At least one (1)

• Definiteness -instructions must be clear and realistic

• Finiteness -must terminate and should have a


starting point.
• Effectiveness -instructions must be efficient
and useful
Logic Formulation

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?

Terminal block Initialization


Block
Process block Connector
Input/Output
block Flow Lines
Decision block
Flowchart Lines

• Indicated by straight lines with arrows


to show the direction of data flow
• Used to connect blocks by exiting
from one and entering another
Terminal block
• Ovals or rounded rectangles are used
to indicate the start and the end og a
module or program

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’

Print “You’re a Print “You’re a


male” female”

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

Print “True” Print “False”

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”

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy