Professional Documents
Culture Documents
Rimsha Ahmad 1
Rimsha Ahmad 1
SUBMITTED TO:
SIR MALIK RIZWAN
07/03/2022
An algorithm is a step by
step procedure to solve a problem. The process of solving a problem
becomes simpler and easier with the help of an algorithm. It is better to
write an algorithm before writing the actual computer program.
PROPERTIES OF ALGORITHM:-
ADVANTAGES OF ALGORITHM:-
1. Reduced complexity:
Writing algorithm and program separately simples the
overall tasks. While writing the algorithm, we can
focus on solving the problem instead of concentrating
on a particular language.
2. Increased flexibility:
Algorithm is written so that the code may be written in
any language. Using the algorithm, the program can
be written in VISUAL BASIC, JAVA or C++ etc.
3. Ease of understanding:
It is not necessary to understand a particular
programming language to understand an algorithm. It
is written in English like manner.
DISADVANTAGES:-
4. Only one flow line should enter and come out of the process
symbol.
5. Only one flow line can enter a decision symbol. However, two
flow lines can come out of it.
Start End
1. Start /terminal:
Oval is used to represent the start or end of the
flowchart.
Example:
The following example displays the start and end steps in the
flowchart.
START END
2. Input/output:
Parallelogram is used to represent an input or output step in
the flowchart.
Example:
The following example displays the input and output steps in the
flowchart.
3. Process:
Rectangular is used to represent a processing or
computational operation in the flowchart.
4. FLOW LINES:
Arrows are used to represent the direction of flow in the flowchart.
There are four flow lines to represent four directions.
5. Decision:
Diamond symbol is used to represent decision step in the
flowchart. It will go in two directions. It goes to one
direction if condition is TRUE or YES and to second
direction the condition is FALSE or NO.
6. Connecter:
Circle symbol is used to combine different flow lines. It
is used when two or more flow symbols come from
different directions and move to one direction.
7. Function call:
Rectangular symbol with double lines on left or right is
used to call a function. The name of a function with
parameters is written inside the symbol.
8. Preparation:
This symbol is used with for loops to specify start a stop
condition.
PROGRAMS:
Example 1:
The following algorithm inputs two numbers
calculates sum and then displays the result on screen.
1) Start
2) Input A
3) Input B
4) Total =A+B
5) Displays total
6) Exit
Flowchart:
Start
Start
Input a, b
Sum= a+b
Print sum
End
Program 1:
#include<studio>
#include<conio.h>
Void main ()
Into a, b, sum;
Sum=a+b;
getch ();
Example 2:
The following algorithm inputs radius from the user
and calculates the area of a circle. (Hint area
=3.14*radius*radius)
1) Start
2) Input radius in r
3) Area=3.14*r*r
4) Print area
5) End
Flowchart:
Start
Input radius
Radius=3.14*r*r
Print area
End
Program 2:
#include<studio>
#include<conic>
Void main ()
int r;
{
Printf (“enter radius”);
Scanf (“%d/n, &r);
R=3.14*r*r
}
getch ();
Example 3:
The following algorithm calculates the distance
covered by a car moving at an average speed of Vm/s in
time T. it inputs the average speed v and time t.(hint:
s=vt where s is the distance traveled ).
1) Start
2) Input average speed in v
3) Input time in t
4) S=v*t
5) Print s
6) End
Flowchart:
Start
Input time in t
Print s
End
Program 3:
#include<studio>
#include<conic>
Clrscr ();
int v, t, s;
{
Printf (“input average speed in v”);
Scanf (“%d/n, &v);
Printf (“input time in t”);
Scanf (“%d, &t”);
Printf (“s=v*t”);
}
getch ()
Example 4:
The following algorithm finds the sum of first fifty
natural numbers.
1) Start
2) Sum = 0
3) N = 0
4) Repeat step 5 and 6 while (N <=5)
5) Sum =sum + N
6) Print sum
7) End
Flowchart:
Start
Sum=0
N =0
Program 4:
#include<studio>
#include<conic>
Void main ()
int n;
{
Sum=sum+n
getch ()
Example 5:-
The following algorithm display Pakistan for 5
times.
1) Start
2) Input Pakistan
3) Display Pakistan
4) End
Program 5:
#include<studio>
#include<conic>
Void main ()
Int n;
Printf (“Pakistan/n”);
N++;
getch ()
Flowchart:
Start
Input Pakistan
Display Pakistan
End