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

PF FALL 2020 - Lab 2

This document discusses programming fundamentals and flowcharts. It provides examples of writing algorithms using pseudocode and examples of different types of flowchart structures, including sequential, decision, and loop structures. It also provides tasks for students to write algorithms and draw flowcharts for problems involving addition, repetition, decision-making, and other logical operations.

Uploaded by

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

PF FALL 2020 - Lab 2

This document discusses programming fundamentals and flowcharts. It provides examples of writing algorithms using pseudocode and examples of different types of flowchart structures, including sequential, decision, and loop structures. It also provides tasks for students to write algorithms and draw flowcharts for problems involving addition, repetition, decision-making, and other logical operations.

Uploaded by

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

CL118 Lab 02

Programming Pre-Programming
Fundamentals phase

Semester FALL 2020


NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES
LAB 02

Learning Objectives
This lab will cover the following topics:

 Writing an algorithm
• Introduction to flow chart
• Structuring a program by using flow charts

I. Writing the Algorithm (Pseudo code)


– Pseudo code means an imitation computer code.
– It is used in place of symbols or a flowchart to describe the logic of a program. Thus, it
is a set of instructions (descriptive form) to describe the logic of a program.
– Pseudo code is close to the actual programming language.
– Using the Pseudo code, the programmer can start to write the actual code.

Example: write an algorithm and draw flowchart to “Buy a pen”


Algorithm:
Step1: Start
Step2: Go to stationary shop
Step3: Select a pen
Step4: Pay the price
Step5: Take the pen
Step6: Come back home
Step7: Stop
Example: find the sum of 5 numbers
Algorithm:
Step1: Start
Step2: Initialize sum = 0 and count = 0 (PROCESS)
Step3: Enter n (I/O)
Step4: Find sum + n and assign it to sum and then increment count by 1 (PROCESS)
Step5: Is count < 5 (DECISION)
Step6: if YES go to step3
else
Print sum (I/O)
Step6: Stop

I. Drawing the Program Flowcharts


– Flowchart is the graphic representations of the individual steps or actions to implement a
particular module.
– The flowchart can be likened to the blueprint of a building. An architect draws a blueprint
before beginning construction on a building, so the programmer draws a flowchart before
writing a program.
– Flowchart is independent of any programming language.
– Flowchart is the logical design of a program.
– It is the basis from which the actual program code is developed.
– Flowchart serves as documentation for computer program.
– The flowchart must be drawn according to definite rules and utilizes standard symbols
adopted internationally.
The International Organization for Standardization (IOS) was the symbols shown below
(You can draw the symbols using ready-made flowcharting template):
Flowchart is a diagrammatic representation of sequence of logical steps of a program.
Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and
process/data flow.
Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.

1|Page
Guidelines for Developing Flowcharts
These are some points to keep in mind while developing a flowchart −
 Flowchart can have only one start and one stop symbol
 On-page connectors are referenced using numbers
 Off-page connectors are referenced using alphabets
 General flow of processes is top to bottom or left to right
 Arrows should not cross each other

Example:
Structuring a Program by using flow charts
1. Use Modules
2. Use logic structures
a. Sequential structure
- Executes instructions one after another in a sequence.
b. Decision structure
- Branches to execute one of two possible sets of instructions.
c. Loop structure
- Executes set of instruction many times.
3. Eliminate rewriting of identical process by using modules.
4. Use techniques to improve readability including four logic structure, proper
naming of variables, internal documentation and proper indentation.
b. Sequential structure:
Example: Draw a flow chart that will allow the user to input 3 integers and have the sum
calculated and outputted.

c. Decision structure
Example: Today it is raining! Draw a flow chart which ask about raining outside and take the
decision of taking an umbrella with himself for going outside.
d. Loop structure
Example: Draw a flow chart that find the sum of five numbers.
LAB TASK

Task# 01:
Write an algorithm and also draw a flowchart that performs addition of two numbers?

Task# 02:
Write an algorithm and also draw a flowchart that prints hello world 10 times?

Task# 03:
Write an algorithm and also draw a flowchart to login to Facebook account?

Task# 04:
Write an algorithm along with drawing a flowchart to find a number that whether it
is even or odd.

Task# 05
Illustrate the following statement by drawing a flow chart. “A lamp in a room is
not working, check if it is not plugged in, do plug it or check whether it might be
burned out so replace it if not then repair it.”

Task# 06
Write Algorithm & Flowchart to print multiplication Table of a number.

Task# 07
Write Algorithm & Flowchart to find if a number is prime or not.

You might also like