0% found this document useful (0 votes)
13 views20 pages

Lec 4 - Algorithms Flowcharts Program Design

The document provides an in-depth overview of Flowgorithm, focusing on the use of variables, mathematical operations, loops, and arrays. It explains how variables function as containers for data types, how to perform operations on numeric variables, and the different types of loops available in programming. Additionally, it describes arrays as collections of variables of the same data type, emphasizing their structure and access methods.

Uploaded by

blackeinstein11
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)
13 views20 pages

Lec 4 - Algorithms Flowcharts Program Design

The document provides an in-depth overview of Flowgorithm, focusing on the use of variables, mathematical operations, loops, and arrays. It explains how variables function as containers for data types, how to perform operations on numeric variables, and the different types of loops available in programming. Additionally, it describes arrays as collections of variables of the same data type, emphasizing their structure and access methods.

Uploaded by

blackeinstein11
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/ 20

University Computer

Foundation
Flowgorithm- In Detail

By: Sajjad Hussain Chauhdary


Contents

o1. Flowgorithm in Depth

o2. Flowgorithm: Using Variables? With example


o3. Flowgorithm: Simple Mathematical Operations for Numeric Variables?
o4. Flowgorithm: Using Loops? With examples
o5. Flowgorithm: Array of variables?

2
Flowgorithm: Using Variables?
❖ In order to perform any non-trivial task, computers need the ability to store or remember values.

❖This is done using variables. Variables in computer programs are similar to the variables with which you are already familiar,
used in Mathematics.

❖Variables in computer programs are containers that can store different kinds of numbers or text.

❖Variables in computer programs are of different types according to the kind of values that they store.

❖Values of variables can be changed or modified by different mathematical, logical or text editing operations.

❖These types of variables often differ somewhat from one programming language to the next.

3
Types of Variables with Examples

Data Type Notes Examples


Boolean Stores either Boolean true 0 (false) or 1 (true)
or false
Real Stores a real number. -1.5,0, 1000.34,
12986.354829, -205.32,
Integer Stores an integer number. Values such as -3, -2, -1, 0,
1, 2, 3 but can't store
numbers such as 3.2, 4.5
String Stores textual data. “Sajjad”, "computer", and
"Year 1947" are all strings.

ADD FOOTER HERE 4


Simple Mathematical Operations for Numeric Variables
In addition, the numeric variables (i.e., integer and real type variables) can be operated upon using
various operators. In addition to the basic operators of + (addition), - (subtraction), * (multiplication), and /
(division); here are a few other symbols you can use to evaluate expressions of numbers, or variables
containing numbers.

Expression Result Notes


2
1 + 3 ^ 2 10 1+3
10 * 2 + 5 * 6 50 10 * 2 and 5 * 6 have higher precedence than addition. The addition is
done last.

7 * (4 - 1) 21 Parenthesis are used for subexpressions, which are evaluated as a whole.


6 / 3 * 2 4 In mathematics, multiplication and division have the same precedence
levels. So, they are evaluated left-to-right. The "PEMDAS" acronym, used in
high-school, is a tad misleading.
10 mod 3 1 Modulo math gives the remainder from division
10 % 3 1 Same expression, but using the C-Family operator

5
Example 1:
Step 1: Start with a blank new Flowgorithm project. Add a Declare block between the Main
and End blocks.

Step 2: Double-click on the Declare block which will then display a property window for the
Declare block. We must give the variable a name and decide what type the variable is going to
be. We call the variable "X" and make it of type Real. Click the OK button.

6
Step 3: After variable X is created, we need to get a number from the user as the input and
store it in X. Click the arrow coming out of the Declare block.

Step 4 : Now, double-click on the Input block to open its property window. It will require the
name of the variable given by the user will be stored. In our case, that is variable X. Enter X into
the input field and click the OK button.

7
Thus far, the flowchart creates a variable X, asks the user for a real number as input, and
stores it in variable X.

Step 5: Now we will compute the cube of X, i.e., and display the result. To display a value, we
need an Output block. Click the outgoing arrow from the Input block and add a new Output
block to the flowchart.

8
Step 5: Double-click on the Output block to open its property window. The Output block requires
the name of a variable or an expression that produces a value that can be displayed. Since we
wish to compute the cube of X, we enter X*X*X. The * character represents the multiplication
operation (). Alternatively, we could type in X^3, where the ' ^ ' represents exponentiation. Click
the OK button.

9
10
Flowgorithm: Using Loops?

❖ Repetition is an essential element of computer programs.


❖ The structure used to define repetition in computer programs is called a loop.
❖ Computer code, or in the case of executable flowcharts like we are using, sequences of blocks, is
put inside a loop and is run repeatedly and is called the body of the loop.
❖ Each execution of the code inside a loop is called an iteration.
❖ All loops are the same in one key aspect.
❖ Before or after each iteration, it checks if a certain condition specified by the programmer is still
true or not.
❖ If the condition is still true, it executes another iteration.
❖ If it is not, the loop is exited, and the program continues to execute beyond the loop.
❖ As we will see in this section, loops are mainly three different types:

1. For loop
2. While loop
3. Do-while loop:

11
For loop : A For loop is usually used when it is known beforehand how
many times the body of the loop is to be executed. The sequence of
execution in a For loop is "condition check – execute - condition check -
execute —...-condition check - exit".

The example, to the right, prints the numbers from 1 to


100. The loop executes 100 times. The value of 'n' starts
at 1 and increases by 1 each time the loop executes. The
loop ends when 'n' reaches 100.

12
While loop: A While loop is usually used when it is not known beforehand how many times the
body of the loop is to be executed, i.e., the condition that is checked becomes true after an
unknown number of times. The sequence of execution in a While loop is the same as in a For loop
"condition check execute - condition check - execute - . . . - condition check - exit" etc.

The example, to the right, declares an integer called


'age'. It then reads the age from the keyboard.
Finally, an If Statement checks if the age is greater than
or equal to 18. Based on this, it either takes the false
branch and displays "Sorry, not yet", or takes the true
branch and displays "Go vote!".
13
Do-while loop: like the While loop, is used when it is not known beforehand how many
times the body of the loop is to be executed. The sequence of execution in a Do-while loop is
"Execute - condition check - execute - ...- condition check - exit", etc., which is different from a
For loop or a While loop.

The example, to the right, prints the numbers from 1 to


100. The assignment statement "n = n + 1" increments the
variable 'n' by 1 for each iteration of the loop.

14
Flowgorithm: Array of variables?
Array: If a variable is a container that stores a value, you can think of an array as a list of
variables, each of which can store a different value.
• Every variable in an array is also called an element of that array.
• All elements of an array are of the same data type, i.e., Integer, Real, String or Boolean.
• Just as variables can be accessed by their names, each element of an array can be
accessed by the name given to the array and a number indicating its location in the array.

15
16
17
18
19
Questions

20

You might also like