Kontera

Wednesday, March 9, 2011

Algorithms and Flow Charts

Algorithm

Def: The step by step execution of a given problem is called Algorithm

Flow Chart

Def: Pictorial representation of an algorithm is called Flow Chart.


RAPTOR
RAPTOR is a flowchart-based programming environment, designed specifically to help students visualize their algorithms and avoid syntactic baggage.  RAPTOR programs are created visually and executed visually by tracing the execution through the flowchart.  Required syntax is kept to a minimum.  Students prefer using flowcharts to express their algorithms, and are more successful creating algorithms using RAPTOR than using a traditional language or writing flowcharts without RAPTOR.

Examples
Roots of Quadratic Equation
Algorithm

Step  1:         Start
Step  2:         Read Coefficients a,b,c
Step  3:         db2-4ac
Step  4:         if (d=0) Then goto Step5 Else goto Step8
Step  5:         r1 -b/2a
Step  6:         r2-b/2a
Step  7:         Print r1, r2 goto Step13
Step  8:         if (d>0) Then goto Step9 Else goto Step12
Step  9:         r1 -b+sqrt(d)/2a
Step 10:        r2 -b-sqrt(d)/2a
Step 11:        Print r1, r2 goto Step13
Step 12:        Print “Roots are Imaginary”
Step 13:        Stop





Flow Chart





Decimal to Binary Conversion

Algorithm

 Step 1:         Start
Step 2:          Read Decimal number “dec”
Step 3:          Set bin 0,i 1
Step 4:          if (dec=0) Then goto Step9 Else goto Step5
Step 5:          r dec%2
Step 6:          bin bin + r * i
Step 7:          dec floor (dec/2)
Step 8:          i i*10 goto Step4
Step 9:          Print “Binary Equivalent “ bin
Step10:         Stop

 Flow Chart



 Reverse of a Given Number
Algorithm
Step1:           Start
Step2:           Read the Number “number”
Step3:           Set rev 0
Step4:           if (number=0) Then goto Step8 Else goto Step5
Step5:           r ← number%10
Step6:       rev ← r + rev*10
Step7:       number ← floor(number/10) goto Step4
Step8:       Print “Reverse Is” rev
Step9:       Stop

Flow Chart


2 comments: