An algorithm is a finite set of sequence to solve a class of problems. This may be defined as a sequence of instructions designed in such a way that if the instructions are executed in the specified sequence, the desired result will be obtained.


  1. An algorithm may take some input that should generate some output.
  2. Each algorithm should be terminated after a finite number of steps and finite amount of time.
  3. Each step should be definite, clear and non ambiguous.
  4. One or more instructions should not be repeated infinitely. This ensures that the algorithm will ultimately terminate. This ensures that the algorithm will ultimately terminate.
  5. The steps of an algorithm should be basic and primitive enough for a computer to understand and how is to be done should be specified.
  6. The steps of an algorithm should be complete.


Let us start with the easiest example.

Algorithm to Add two Numbers:

(Add two numbers) variable declaration A, B as real are inputs here and C as real is to store output.

Step1: Start
Step2: Read: A, B.
Step3: Calculate: C = A + B.
Step4: Print: C.
Step5: Exit

Flowchart to Add two Numbers:


Algorithm to solve Quadratic Equation:

The solution of the quadratic equation ax2+bx+c = 0 where a ≠ 0, are given by the quadratic formula x = { -b + (b2 – 4ac)1\2 } / 2a and x = { -b – (b2 – 4ac)1/2 }./ 2a.
Here D = b2 – 4ac is called as the discriminant of the equation. The nature of the roots can be as:

  • If D is negative then the roots are imaginary.
  • If D is positive then the roots are real and unequal.
  • If D is zero then the roots are real and equal.

(Quadratic equation) Coefficients a, b and c of a quadratic equation are taken as input and real solutions are produced as output, if any.

Step1: Read: a, b, c.
Step2: Set D: = b2 – 4ac.
Step3: if D > 0 then:
Set X1 := { -b + (D)1/2} / 2a
Set X2 := { -b + (D)1/2} / 2a .
Write: X1, X2.
Else if D = 0, then:
Set X := -b / 2a.
[End if structure.]
Step4: Exit

Quadratic Equation Flowchart:


Algorithm to Find Largest Element in an Array:

(Largest element in an Array) An array DATA having N numeric value is given. This algorithm finds the location LOC and the value MAX of the largest element of DATA. The variable i is used here as a counter.

Step1: [Initialize] Set i := 1, LOC := 1 and MAX = DATA[1].
Step2: [Increment counter] Set i := i + 1.
Step3: [Test counter] If i > N, then:
Write: LOC, MAX and Exit.
Step4: [Compare and update] If MAX < DATA[i], then
Set LOC := i and MAX := DATA[i].
Step5: [Repeat loop] Go to Step2.

Prime Number Algorithm:

PRIME NUMBER: A number which is divisible by either 1 or by self is called prime number. Examples of prime numbers are 2, 3, 5, 7, and 11 and so on.

NON PRIME NUMBER: Those Number which are divisible by 1, by self and by some other numbers too then those numbers are called non prime numbers. Examples of non prime number are 4, 6, 8, 9 and 10 and so on.

(Prime and Non Prime) Let N be any positive integer. This algorithm decides whether the given number N is prime number or non prime number. i is used here as a counter. Flag is variable to store either 1 or 0.

Step1: Start
Step2: [Initialize counter] i := 2 and Flag := 0
Step3: Repeat while i < N then:
If N % i == 0 then:
Flag := 1
[End of If structure]
i :=  i + 1
[End of while loop]
Step4: If Flag :== 0 then:
Print: N is prime number.
Print: N is non prime number.
Step5: Exit

Related Posts

  • ALGORITHM FOR ALMIGHTY FORMULAALGORITHM FOR ALMIGHTY FORMULA Almighty Formula is an alternative name of Sridharacharya formula. This formula is used to find the roots of a quadratic equation. Any equation in form of ay2 + by + c = 0 is known as […] Posted in ALGORITHM
  • ALGORITHM FOR MATRIX OPERATIONSALGORITHM FOR MATRIX OPERATIONS Their are different Matrix operations like Matrix addition, Matrix Subtraction, Matrix Multiplication, Inverse of a Matrix and Transpose of a Matrix. Here algorithm for matrix operations […] Posted in ALGORITHM
  • Flowchart to find sum of digits of a NumberALGORITHM TO FIND SUM OF DIGITS OF A NUMBER (Sum Of Digits Of A Number) Suppose N is an integer. This algorithm adds the digits of number N. As for example if N is 12345 then Sum of digits will be 15 by performing operation 1 + 2 + […] Posted in ALGORITHM
  • ALGORITHM FOR PALINDROMEALGORITHM FOR PALINDROME Any word, number or phrase which reads same from both ends is palindrome. For example 77, 121, 1331 and 12321 are palindrome numbers. Similarly Dalda and Madam are palindrome […] Posted in ALGORITHM