0% found this document useful (0 votes)
36 views5 pages

Document 2

This document discusses algorithms, their characteristics, and how to write them. An algorithm is a step-by-step procedure to solve a problem written in a clear, unambiguous way. It must have precise instructions, a finite execution time, a termination condition, and accept inputs to produce an output. When writing an algorithm, the name, start, inputs/outputs, step numbers, notes, and end must be specified. Flowcharts can also represent algorithms pictorially using standard notations to help understand the program logic. Examples are given of algorithms and flowcharts to add numbers and calculate simple interest.

Uploaded by

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

Document 2

This document discusses algorithms, their characteristics, and how to write them. An algorithm is a step-by-step procedure to solve a problem written in a clear, unambiguous way. It must have precise instructions, a finite execution time, a termination condition, and accept inputs to produce an output. When writing an algorithm, the name, start, inputs/outputs, step numbers, notes, and end must be specified. Flowcharts can also represent algorithms pictorially using standard notations to help understand the program logic. Examples are given of algorithms and flowcharts to add numbers and calculate simple interest.

Uploaded by

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

Algorithm:

⦁ It is a step-by-step procedure to solve a problem


⦁ A sequential solution of any problem that is written in natural language.
⦁ Using the algorithm, the programmer then writes the actual program.

⦁ The main use of algorithm is to help us to translate English into C.


⦁ It is an outline or basic structure or logic of the problem.

Characteristics of Algorithm
⦁ Each and every instruction must be precise and unambiguous

⦁ Each instruction execution time should be finite.


⦁ There should be a termination condition.
⦁ It must accept 0 or more inputs and produce compulsory an output.
⦁ It can accept any type of input and produce a corresponding output.

General Way of Writing the Algorithm


⦁ Name of the algorithm must be specified.
⦁ Beginning of algorithm must be specified as Start
⦁ Input and output description may be included
⦁ Step number has to be included for identification

⦁ Each step may have explanatory note provided with in square bracket followed by
operation.
⦁ Completion of algorithm must be specified as end or stop.
Ex 1: Write an algorithm to add two numbers
Algorithm: Addition of two numbers Input: Two number a and b
Output: Sum of two numbers
Step 1: Start
Step 2: [input two number] Read a and b
Step 3: Sum = a + b [compute its addition]
Step 4: print Sum
Step 5: Stop

Ex 2: Write an algorithm to compute simple interest


Algorithm: To find Simple Interest
Input: p, t, r
Output: SI
Step 1: Start
Step 2: [input a principle p, time t and rate r] Read p, t, r
Step 3: [compute simple interest] SI (p*t*r)/100
Step 4: display SI
Step 5: Stop
Flow charts:
⦁A flowchart is a pictorial or graphical representation of an algorithm or a
program.
⦁It consists of sequences of instructions that are carried out in an algorithm.
⦁The shapes represent operations.
⦁Arrows represent the sequence in which these operations are carried out.
⦁It is mainly used to help the programmer to understand the logic of the program.
Notations used in flowchart
Ex 1.Algorithm and Flowchart to Input the dimensions of a rectangle and print
its area
Step 1: Start
Step 2: [input the values of length and breadth]
read length, breadth
Step 3: [Compute ‘area’]
area= length * breadth
Step 4: display area
Step 5: Stop

FLOWCHART:

You might also like