You are on page 1of 15

COMPUTER

PROGRAMMING
Lecture 04
Unit 1 Problem Solving
Syllabus
Objecti
ves

2
Understand the basics symbols of
1 flowcharts

Understand the logic of algorithm and flow of


control.
Algorithm
An algorithm is well defined, finite set of computational
instructions that accomplishes a particular task, which may or
may not take inputs and produces some value or a set of
values as output. In addition all algorithms must satisfy the
following criteria:
1.Zero or more quantities are externally supplied: input
2.At least one quantity is produced: output
3.Each instruction is clear and unambiguous: Definiteness
4.The algorithm terminates after a finite number of steps:
Finiteness
5.For every input instance, it halts with the correct output:
Correct.
Conventions used in writing Algorithms
Name of Algorithm
Introductory Comments
Steps
Comments
Algorithm Development
Ex- Find maximum of 3 numbers. The variables used are:x, y, z : type
integer
big : Storing the value of the largest number, type integer

1
Step 1: [input the three integers]
read x, y, z
.

Step 2: [compute the largest of three numbers]

2 big = x;
If(y>big) big=y
If(z>big) big=z

3 Step 3: [Write the largest number]


Write (big)

4 Step 4: [Finished] exit


Flowchart

Definition:- A flowchart is graphical or pictorial


representation of an algorithm.
It shows the logic of algorithm and flow of control.
Flowchart uses the symbol to represent the specific
action and arrow to indicate the flow of control.
Basic symbols of flowchart
Basic Flowchart Symbols

Notice there are three types of symbols in this flowchart:


rounded rectangles

parallelograms

a rectangle

Each symbol represents a different type of operation.


Four Flowchart Structures

Sequence
Decision
Repetition
Case
Sequence Structure
A series of actions are performed in sequence
The pay-calculating example was a sequence flowchart.
Ex.- Write an Flowchart for finding the addition of two number.
Decision Structure
One of two possible actions is taken, depending on a condition.
A new symbol, the diamond, indicates a yes/no question. If the
answer to the question is yes, the flow follows one path. If the
answer is no, the flow follows another path.
Ex-

if (x < y)
a = x * 2;
else
a = x + y;
Repetition Structure
A repetition structure represents part of the program that repeats.
This type of structure is commonly known as a loop.
A loop tests a condition, and if the condition exists, it performs an
action.
Then it tests the condition again. If the condition still exists,
the action is repeated. This continues until the condition no longer
exists.
Ex- while (x < y)
x++; YES
x < y? Add 1 to
x
Case Structure
One of several possible actions is taken, depending on the
contents of a variable.
Ex- Find maximum of 3 nos
Question Bank

1.What is algorithm?
2. Explain Steps involved in algorithm development with
suitable example.
3.What is flowchart?
4.Describe the symbol of flowcharts.
5.Draw flowchart for Fibonacci Series.

You might also like