# Representing an algorithm using Flowcharts

## Presentation on theme: "Representing an algorithm using Flowcharts"— Presentation transcript:

Representing an algorithm using Flowcharts
Review: Algorithms are step-by-step definitions given to solve a problem

Flowcharts Many of us find it easier to follow steps when they are represented diagrammatically or graphically. Flowchart shapes are: terminators symbol(start or stop) process symbol(assignments, calculations) input/output symbols (read, write) decision symbol(decisions between 2 options) flow control- flow of steps connector symbol(used to connect sections of a flowchart

Flowchart algorithm1 Write a pseudocode algorithm and a flowchart to find and display the sum of 10 and 20 Start a10 b20 Suma + b Print Sum stop start a10 b 20 suma + b Print sum stop

Flowchart algorithm2 Draw a flowchart that will read 3 numbers and find the product of the 3 numbers
Start Read n1, n2, n3 Productn1*n2*n3 Display product stop start Read n1,n2,n3 Productn1*n2*n3 Print product stop

Flowchart algorithm3 Draw a flowchart that will accept 3 numbers and find and display their average
Start Read n1,n2,n3 Average(n1+n2+n3)/3 Write average stop start Read n1,n2,n3 Average (n1+n2+n3)/3 Write average stop

Write “Enter 2 unequal numbers”
Flowchart algorithm4 Draw a flowchart that will prompt the user to enter 2 unequal numbers and find the largest between them. start Start Write “Enter 2 unequal numbers” Read n1,n2 If n1>n2 then set largen1 else set largen2 Endif Print large stop Write “Enter 2 unequal numbers” Read n1,n2 yes Is n1>n2 no Largen1 Largen2 Write large stop

Flowchart algorithm4 Draw a flowchart that will prompt the user to enter 3 unequal numbers and find the smallest among them. Start Write “Enter 3 unequal numbers” Read num1,num2,num3 If num1<num2 then smallnum1 else small num2 Endif If num3<small then smallnum3 Write small stop Flowchart solution on next slide

Write “enter 3 unequal numbers
start 1 Write “enter 3 unequal numbers Is num3<small yes no Read num1,num2,num3 Smallnum3 Is num1<num2 no yes Write small For additional and more complex questions see Heinemann, page 96 (flowcharts with unbounded iteration) to page99 (flowcharts with bounded iteration) Stop Smallnum1 Smallnum2 1

Question A problem requires you to read 3 numbers and calculate and print the total. Construct: IPO chart Pseudocode Flowchart