0% found this document useful (0 votes)
0 views

Programming-techniques

programming 2

Uploaded by

sultanameer008
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Programming-techniques

programming 2

Uploaded by

sultanameer008
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Algorithms and flow charts

Maham Shuja
[email protected]
Computer
 Computer: A computer is a general-purpose electronic machine
invented to help' people solve various problems Computer must
be programmed by human beings to perform various tasks
programming techniques are used for solving problems on
computer.
OR
 Computer: Computer is an advanced electronic device that
takes raw data as input from the user and processes it under the
control of set of instructions (called program}. gives the result
(output} and saves it for the future use.
Algorithm
 Algorithm: . Algorithm means method,
procedure technique or plan .
 Algorithm is a step- by-step problem solving
method that is easy to understand and follow. It is
a set of steps that clearly define a sequence of
operations to solve a problem.
Role of algorithm in problem solving:
 Algorithms play an important role in computer
programming.
 Computer programming is the process of taking
an algorithm and coding it in a programming
language.
 Formulating an algorithm is the first step for
developing a computer program.
Measuring Efficiency of an Algorithm

The efficiency of an algorithm is the property


which relates the algorithm to the number of
computational resources used in it. An
algorithm must be analyzed to determine its
resource usage (e g. time, memory, and
storage space). For maximum efficiency
we wish to minimize resource usage.
Problem: Find the Sum, Product and
Average of Five given Numbers
 Planning the Solution:
 Input Five given numbers
 Required Output: Sum, product, and average of five numbers.
 Processing. Addition, multiplication, and division of numbers
 Algorithm: Step 1.: Start Let the five numbers be A=2, B=5 ,
C=5, D=4 and E=1 Step 2: FIND the sum (SUM) SUM=A+B+C
+D+E
 Step 3 FIND the product (PROD) PROD=A*B*C*D*E
 Step 4 FIND the average (AVG) AVG=SUM/5
 Step 5 Output SUM, PROD. AVG Step 6 Stop
Problem: Find Acceleration of a Moving
Object for Given Mass and the Force
Applied.

 Planning the Solution:


 Input Mass and the Force
 Required Output: Acceleration of a moving object.
 Processing: Divide the force by the mass
 Algorithm:
 Step 1 Start Let the mass (M) be 50 and the force (F) be 12
 Step 2 CALCULATE the acceleration (A) A = F/M
 Step 3 Output A Step 4 Stop
Problem: Read Marks (II) and Print Letter
Grade According to Input
Planning the Solution:
Input:Marks
Processing. Check in which range the marks fall and accordingly print the
letter grade
Required Output Letter Grade
Algorithm:
Step 1 Start Let the marks be M
Step 2 Compare the marks IF M≥80 THEN print Grade Al otherwise
GOTO Step 4
Step 3. GOTO Step 13
Step 4 Compare the marks IF M≥70 THEN print 'Grade A otherwise
GOTO Step 6
Step 5 GOTO Step 13
Step 6 Compare the marks IF M≥60 THEN print "Grade B'
otherwise GOTO Step 8
Step 7 GOTO Step 13
Step 8 Compare the marks IF M≥50 THEN print "Grade
C." otherwise GOTO Step 10
Step 9 GOTO Step 13
Step 10 Compare the marks IF M≥40 THEN print -Grade
D' otherwise GOTO Step 12
Step 11 GOTO Step 13
Step 12 Compare the marks IF M≥33THEN print Grade F"
otherwise print Grade F
Step 13. Stop
11 QUAID - I - AZAM UNIVERSITY, ISLAMABAD 3/12/2025
Steps for Drawing Flowchart
 The flowchart developer must determine the following
requirements for the given problem or algorithm before
drawing a flowchart.
 1-Input to the flowchart
 2-Type of processing required
 3-Decisions to be taken 4-
 The output to be produced after processing Letter Grade
..... M≥80 and M≤100 Al M≥70 and M
 Input: The flowchart developer must know what exactly the input to the
flowchart is. The input is determined from the problem statement. For
example, the given problem is to convert temperature from Fahrenheit to
Celsius here the input will be the temperature in Fahrenheit.
 Processing: The flowchart developer must decide what type of calculation
is to be. performed or which formula is to be applied to obtain the required
result. For example, to find the area of a triangle the following formula is to
be used.
 Area= (Base * Height)/2
 Decision: The flowchart developer must decide which control structures
(sequence repetition or selection) are to be applied for the solution of the
problem. For example, selection structure must be applied to print letter
grade of a student based on the marks obtained.
 The selection structure will check in which range the marks fall and
accordingly print the grade.
 Output: The flowchart must provide the required output
Graphical Symbols used in Flowchart
 Flowchart: Flowchart is a diagrammatic representation of algorithm.
It describes what operations are required to solve a given problem.
Advantages of using flowcharts:
 Flowchart illustrates the sequence of operations to be performed to
solve a problem in the form of a diagram.
 Computer programmers draw flowcharts before writing
computer programs. It provides an easy way to analyze and find
solutions to problems.
 Once the flowchart is drawn, it becomes very easy to write the
program in any high-level language.
 It is very helpful in communicating the problem-solving method to
other people.
 It also helps in finding and removing errors in computer programs.
Algorithm for making a tea
17 QUAID - I - AZAM UNIVERSITY, ISLAMABAD 3/12/2025
Algorithm for division of non-zero
numbers

18 QUAID - I - AZAM UNIVERSITY, ISLAMABAD 3/12/2025


Thank You

19 QUAID - E - AZAM UNIVERSITY, ISLAMABAD 3/12/2025

You might also like