Professional Documents
Culture Documents
Programming Logic and Design - Dr. Evelyn A. Rodriguez
Programming Logic and Design - Dr. Evelyn A. Rodriguez
RODRIGUEZ
WHAT IS AN ALGORITHM
An algorithm is a finite set of instructions that specify a sequence of operations to be carried
out in order to solve a specific problem or class of problems.
Example. “Apply the shampoo to wet hair. Massage gently. Leave on for a few
minutes. Rinse off.”
FLOWCHART
Initially, algorithms are represented as flowcharts. Flowchart is a traditional graphical tool
using standardized symbol. It is a diagram representing the logical sequence in which combination of
steps or operations is to be performed. It is the most widely used graphic method for describing
computer operations.
2. Preparation / Initialization Symbol – signifies the preparation of data; used to select initial
conditions; used to represent instructions or group of instructions that will alter or modify a
program’s course of execution.
3. Input / Output Symbol – shows input and output. Data are to be read into the computer
memory from an input device or data are to be passed from the memory to an output device.
6. On-page Connector – a non-processing symbol that shows the entry or exit point of the
flowchart.
7. Off-page Connector – a non-processing symbol that designates entry to or exit from one
page when a flowchart requires more than one page.
• Arithmetic Operators
Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
• Relational Operators
Operators Meaning
= Equal
> Greater than
< Less than
<> Not Equal
≥ Greater than or Equal to
≤ Less than or Equal to
• Logical Operators
Operators Meaning
&& AND
|| OR
! NOT
CONTROL STRUCTURES
1. IF Statement
The IF statement is a conditional statement.
Flowchart: Pseudocode:
True False
Condition IF (Condition) then
{
Statement 1 Statement 1
}
Statement 2
Statement 2
2. IF-ELSE Statement
The IF-ELSE statement is a conditional statement that provides the computer with a choice
between two options.
Flowchart: Pseudocode:
3. SWITCH Statement
The SWITCH statement is basically an expansion of the IF-ELSE statement. It provides a
mechanism for choosing an option among several possibilities. An example of flowchart with SWITCH
statement is shown below.
Flowchart:
Start
A
Turn on stove
F N
Water is
boiling?
With Y Put 1 tblspoons of
T milk? milk in mug
Turn off stove
N
Fill mug with boiled water Stir contents
A End
SAMPLE EXERCISE: Given the problem, obtain the algorithm, flowchart, pseudocode, and equivalent
Turbo C++ program.
Problem #1: Compute for the area of the circle. Input the radius and print out the values of radius and
area.
Algorithm:
1. Input the value of radius (R).
2. Define the value of PI (equal to 3.1416).
3. Calculate the area of the circle using the formula AREA = PI*R*R.
4. Print the radius and the corresponding area.
Problem #2: Given three numbers A, B, and C, draw a flowchart to compute and print out the sum,
average, and the product of these numbers.
Algorithm:
1. Read in the values of A, B, and C.
2. Determine the sum (SUM) of the three values read.
3. Compute the average (AVE) by dividing the sum by 3.
4. Multiply the first value by the second value then by the third value to determine the product
(PROD) of the three values.
5. Print out the computed values of SUM, AVE, and PROD.
Start
Compute_SUM_AVE_and_PROD() #include <stdio.h>
{ #include <conio.h>
Input A, B, C
Read A, B, C Compute SUM = A+B+C void main()
Compute AVE = (A+B+C)/3 { int A, B, C, SUM, PROD;
Compute PROD = A*B*C float AVE;
SUM = A+B+C Print SUM, AVE, and PROD clrscr();
} printf (“Enter 1st value:”);
scanf (“%d”,&A);
printf (“Enter 2nd value:”);
AVE = (A+B+C)/3 scanf (“%d”,&B);
printf (“Enter 3rd value:”);
scanf (“%d”,&C);
PROD = A*B*C SUM = A+B+C;
AVE = (A+B+C)/3;
PROD = A*B*C;
Print SUM, AVE, printf (The SUM is %d,
PROD the AVE is %f, and the
PROD is %d.”, SUM,
AVE, PROD);
getch();
End }
Problem #3: Input the student information as follows: student number, student name, course, section
and the midterm and final term grades. Compute the final grade by dividing the sum of midterm grade
and final term grade. Determine the remarks whether passed (75% and above) or if otherwise, failed.
Display the student name, final grade, and remarks.
Algorithm:
1. Input student number (SNo), student name (SName), course (C), section (Sec), midterm
grade (MG), and final term grade (FG).
2. Compute the final grade (FinalGrd) using the formula: FinalGrd = (MG + FG)/2
3. If FinalGrd is greater than or equal to 75, the remark is Passed, otherwise Failed.
4. Output the student name (SName), final grade (FinalGrd), and remarks.
Flowchart:
Pseudocode:
ComputeFinalGrade()
{ Input SNo, SName, C, Sec, MG, FG
Compute FinalGrd = (MG + FG)/2
If FinalGrd>=75
{
Output Sname, FinalGrd, “Passed”
}
Else
{
Output Sname, FinalGrd, “Failed”
}
}
Homework: Choose a partner. Prepare an algorithm, flowchart, and pseudocode of the Enrollment
Process at MinSU Bongabong Campus. The deadline is next meeting, April 5, 2022. I will randomly pick
5 partners who will present their assignment to the class. If your presentation is excellent, the reward
is exemption to our next quiz.