0% found this document useful (0 votes)
175 views12 pages

Flow Charts-Looping

The document provides examples of flowcharts to solve various programming problems and discusses the basic control structures of flowcharts including sequence, decision, and looping. It gives the formulas for computing the perimeter of a circle, distance traveled by a car, and the price of ice. It also provides examples of count-controlled loops, sentinel value termination, and accumulating sums using loops.

Uploaded by

vj hernandez
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)
175 views12 pages

Flow Charts-Looping

The document provides examples of flowcharts to solve various programming problems and discusses the basic control structures of flowcharts including sequence, decision, and looping. It gives the formulas for computing the perimeter of a circle, distance traveled by a car, and the price of ice. It also provides examples of count-controlled loops, sentinel value termination, and accumulating sums using loops.

Uploaded by

vj hernandez
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/ 12

Saturday, 29 August 2020 1:13 pm

A. Flow Charts

Programming Logic and Design Page 1


Review

Write an algorithm and draw the flowchart for each of the following:
1. Draw a flowchart that will compute for the perimeter of the circle. Given the formula
P = 2*pi*R
Where P is the perimeter, r is the radius.

Programming Logic and Design Page 2


[email protected] at 08/09/2020 10:39 am

2. An Auto mobile starts from rest then runs at a speed of a km/hr. Draw a flowchart that will compute for the total
distance traveled if the automobile had been traveling for t hours. Use the formula d=v0t + (at2)/2

3. Draw a flowchart that that will identify if a number entered is negative or positive.

4. Draw a flowchart that will accept three numbers and determines which is the highest and which is the lowest.

Programming Logic and Design Page 3


5. Draw a flowchart that will compute and print for the price of ice given the following conditions
Temperature Price(pesos)
35-37 5
31-34 4
27-30 3
24-26 2
23 and below 0

Basic Control Structure of a Flowchart


Most of the times some part of the program needs to be repeated at a specified number of times or until a condition is
satisfied, the process is called looping. It makes the flow of control in a program dependent on the value of the
specified condition.

1. Sequence (begin..end or start..stop)


In this kind of structure the steps involved follow each other one after It should be noted however that every flowchart
begins and ends with this kind of notation.

2. Decision (if..then..else)
Part of the flowchart that employs two or more possible alternative solution and one of which will be chosen for
execution depending on the value of the given condition.
Example:

3. Loop (while..do, repeat ..until)/Iteration


Loop is part of the flowchart that repeats at a specified number of time. This process is called looping. It can be made
to stop when a certain condition is met or stop at a specified number of repetitions. A counter is needed to keep track
at the number of times a loop is executed. Failure to set the condition will cause the loop to iterate indefinitely.

Programming Logic and Design Page 4


In a Repeat...Until loop, the process is executed first then the condition is tested. If the value of the condition returns
False the control is returned to repeat the process; otherwise the True statement is executed

Note: Counters are usually initialized at the beginning of the program

Designing a Loop
There are three things to consider in designing a loop:
1. The body
2. The initializing statement
3. The conditions for terminating a loop

Methods for Terminating a Loop


There are various ways of terminating a loop. Each way depends on the given condition of the problem

1. Count controlled loop


The user ask for the number of times a loop is to be repeated.

2. Ask before iterating


The user is prompted after each loop whether or not a loop is iterated again

3. Using a sentinel value


The user assigns a sentinel value to terminate a loop. Sentinel has a value that is distinct so that it will indicate the
end of the loop. A good example is when a program reads in positive integers, a negative number can be used as a
sentinel value.

4. Running out of input


A loop that runs out of input will terminate with an error.

5. Exit on a Flag condition


This condition uses a variable that changes its value to indicate that some event has taken place.

Examples (Looping and Iteration)


1. Write a flowchart to add natural numbers from 1 to 5

Programming Logic and Design Page 5


2. Draw a flowchart that add first N numbers

3. Draw a flowchart that accepts 5 numbers. Determine if the numbers entered are odd or even. Compute for the total of
all odd numbers, all even numbers, and the total of all numbers.

So Se St C n
0 0 0 1 5
5 0 0 2 4
5 4 0 3 8
5 12 0 4 11
16 12 0 5 7
23 12 35

Programming Logic and Design Page 6


Flowchart that accepts a number then output the
sum of the squares from 1 to n.

Flowchart that will compute for the sum of even


numbers until a number 1 is entered.

Programming Logic and Design Page 7


Programming Logic and Design Page 8
Programming Logic and Design Page 9
Programming Logic and Design Page 10
Programming Logic and Design Page 11
Programming Logic and Design Page 12

You might also like