Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

ASSIYNEMENT: ALOGRIYHM

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:-

Different properties of an algorithm are as


follows:

 The given problem should be broken down into simple and


meaningful steps.
 The steps should be numbered sequentially.
 The steps should be descriptive and written in simple English.

ADVANTAGES OF ALGORITHM:-

Some advantages of algorithm are as follows:

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:-

1) Algorithms are time consuming.


2) Big tasks are difficult to put in algorithm.
3) Difficult to show branching and looping in algorithm.
4) Understanding complex logic through algorithm can be very
difficult.
Flowchart:-
Flowchart is a combination of two words flow and chart. A
chart consists of different symbols to display information about any
program. Flow indicates the direction of processing takes place in the
program.

Flowchart is a graphical representation of an algorithm. It is a way of


visually representing the flow of data, operations performed on data and
sequence of these operations. Flowchart is designed to the according
rules:

Uses of logical flowchart:-


Flowchart is used for the flowing reasons.

1) Flowchart is used to represent an algorithm in simple logical


manner.
2) Flowchart is used to show the steps of an algorithm in an easy way.
3) Flowchart is used to understand the flow of program.
4) Flowchart is used to improve the logic for solving the problem.
5) Programs can be reviewed and debugged easily.

Guidelines for drawing flowchart:


Different guidelines for drawing a flowchart are as follow:

1. All necessary requirements should be listed in a logical order while


drawing a flowchart.
2. Flowchart should be clear, neat and easy to follow.
3. The flow of flowchart can be form left to right and top to bottom.

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.

6. Only one line can be used in start and end symbol.

Start End

7. The intersection of flow line should be avoided.


8. The comments should be written in remark symbol.

these are comments.

9. The connector should be used to reduce the number of flow lines if


the flowchart become complex.
10.It is useful to ensure the volatility of flowchart by testing it the
sample data.
SYMBOLS:
The standard symbols are used to draw a flowchart. The
commonly used standard symbols are as follow:

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.

INPUT OUTPUT MARKS

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;

Print (“Enter two numbers”);

Scanf (“%d, %d&%d”, &a, &b, a+b);

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 average speed

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;
{

Printf (“enter number”);

Scanf (“%d, %d&%d, &n, &s,&n+s”);

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

You might also like