Algorithm
By Arup Medhi
What is Algorithm
The methodology for problem solving
using a computer is known as
algorithm. An algorithm gives a step by
step instruction that could be converted
into statements in a programming
language understandable by a
computer.
The rules that govern algorithm
are as follows: -
1. The algorithmic steps must be
definite not be ambiguous. It cannot
contain vague statements or
inconclusive statements, such as
dividing by zero.
2. An algorithm might receive zero or
more inputs.
3. An algorithm should terminate at some
point in time. It must not contain any endless
loop.
4. An algorithm should be well structured
with the first instruction on the top of the
program.
5. An algorithm should be validated by
chosen sample inputs, it should be possible to
prove that the algorithm solves the problem
correctly with valid and invalid inputs.
An algorithm to find area of
a square
Step 1: Start
Step 2: Input x
Step 3: Area = x * x
Step 4: Print Area
Step 5: End
An algorithm to check whether an
input no is divisible by 5 or not.
1. Start
2. Read x
3. Rem= x mod 5
4. If Rem=0, go to Step 6
5. Else, Print, “The number is not
divisible by 5”. End
6. Print “The Number is divisible by
5.” End
A sample algorithm to find out whether a
triangle with given sides is right angled or not
1. Start
2. Read side1, side2 and side3
3. Find the square root of (side2 square + side3 square)
4. If it is equal to side1, go to step 10
5. Else, find the the square root of (side1 square + side3 square)
6. If it is equal to side2 go to step 10
7. Else, find the the square root of (side1 square + side2 square)
8. If it is equal to side3 go to step 10
9. Else, print, “the sides don’t form a right angled triangle”.END
10. Print, “The sides form a right angled triangle”. END
Write an algorithm to check whether
an input no is odd or even
Answer:-
1. Start
2. Read x
3. Rem= x mod 2
4. If Rem=0, go to Step 6
5. Else, Print, “The number is odd”. End
6. Print “The Number is even.”. End
Write an algorithm to find the sum
of two numbers
Answer:-
1. Start
2. Read x, y
3. sum= x + y
4. Print sum
5. End
Home Assignment
Write an algorithm to find the largest
among three input integers.
1. Start
2. Read A, B, C
3. If (A>B) , go to step 5
4. Else, go to step 7
5. If ( A>C), Print, “A is the largest number.” END.
6. Else, Print, “C is the largest number.” END.
7. If (B>C), Print, “B is the largest number.” END.
8. Else, Print, “C is the largest number.” END.
Thank You