0% found this document useful (0 votes)
28 views16 pages

Introduction To Computer Programming Problem Solving & Algorithms

The document provides an introduction to flowcharts and pseudocode for representing algorithms. It defines flowcharts as using blocks and arrows to visually represent the steps in an algorithm. Common flowchart symbols like terminals, flow lines, processes, and decisions are described. Pseudocode uses English-like syntax to describe algorithms in a way that resembles typical programming languages. It discusses using variables, sequential input/output operations, conditional "if/else" statements, and iterative looping to represent basic algorithm operations in pseudocode.

Uploaded by

Alpha Romeo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views16 pages

Introduction To Computer Programming Problem Solving & Algorithms

The document provides an introduction to flowcharts and pseudocode for representing algorithms. It defines flowcharts as using blocks and arrows to visually represent the steps in an algorithm. Common flowchart symbols like terminals, flow lines, processes, and decisions are described. Pseudocode uses English-like syntax to describe algorithms in a way that resembles typical programming languages. It discusses using variables, sequential input/output operations, conditional "if/else" statements, and iterative looping to represent basic algorithm operations in pseudocode.

Uploaded by

Alpha Romeo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to Computer

Programming
Problem Solving & Algorithms
Jehangir Arshad Meo

Lec#5

Mechanical Engineering Department

COMSATS Institute of Information Technology

Sahiwal
Flow Charts
 A flowchart is a visual or graphical representation of an algorithm.

 The flowchart employs a series of blocks and arrows, each of which


represents a particular operation or step in the algorithm.

 The arrows represent the sequence in which the operations are


implemented.

2
Flowcharts – Most Common Symbols
SymbolName Function
Terminal Represents the beginning or end of a program.

Flow-line Represents the flow of logic.

Process Represents calculations or data


manipulation.

Input / OutputRepresents inputs or outputs of data and


information.

Decision Represents a comparison, question, or decision,


that determines alternative paths to be followed.

3
Flow Charting
Expresses the flow of processing in a
structured pictorial format.

Flow
Input and Processing of
Output Steps Steps data

Decision Terminator
Connectors

4
Begin
Flow chart for
Converting
Get temp. in ‘F’
Fahrenheit
into Celsius
5
Calculate C(F32
)
9

Print ‘C’

Stop

5
Flow chart for
Get three scores
calculating
Add them together average of
three scores
Divide the result by three

Print the average

Yes No
More students? Stop

6
Comparison of Algorithm representations in Natural language,
flowchart and Pseudo-code
START

INPUT
Step 1: Begin the calculations A, B
BEGIN Adder
Step 2: Input two values A and B Input A and B
C = A + B
Add A to B
Step 3: Add the values PRINT C
and store in C
END Adder
Step 4: Display the result

Step 5: End the calculation OUTPUT


C

END
Natural language Flowchart Pseudo-code
7
Pseudo-code
Computer scientists use pseudo-code to express
algorithms:
English like constructs (or other natural language), but

modeled to look like statements in typical programming


languages.

8
Pseudo-code:
Three basic kind of operations:
Sequential
Computation ( Set … )
Input/Output ( Get ... / Print ... )
Conditional
If … Else
If …
Iterative / looping
Repeat ...
While ...

9
Variables
A variable is a named storage.
- A value can be stored into it, overwriting the
previous value
- Its value can be copied
Examples:
Set the value of A to 3
The variable A holds the value 3 after its execution
Set the value of A to (A+1)
Same as: add 1 to the value of A ( A is now 4)

10
Sequential Operations - Input/Output

Input
Outside world
Output

•The Computer needs to communicate with


the outside world:
 INPUT operations allow the computing agent to receive
from the outside world data values to use in subsequent
computations.
 OUTPUT operations allow the computing agent to
communicate results of computations to the outside
world.

11
Input
General format:

Get a value for <variable>


The computing agent (computer) suspends executions and
waits for an input value.

12
Output
General format:

Print the value of <variable>


Print the message, "<text>"

The computing agent (computer) displays the value of


the variable(s).

13
Example
Write an algorithm to calculate the average of three
numbers.
Steps Operations
1 Get values for N1, N2, and N3
2 Set the value of Average to (N1+N2+N3)/3
3 Print the value of Average
4 Stop

14
Conditional Operations
If <condition> then
operations for the then-part
Else
operations for the else-part

1. Evaluate <condition> expression to see whether it is true or


false.
2. If true, then execute operations in then-part
3. Otherwise, execute operations in else-part.

15
Conditions, or Boolean Expressions

A condition is one whose value is true or false, for


example:
 3>2 is greater than (true)
 3=2 is equal to (false)
 A>2 is true if A’s value is greater
than 2 (at the time this is
executed), false otherwise.

16

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