Sei sulla pagina 1di 6

Algorithm & flow charts

Algorithm: An Algorithm is a step by step method for solving a problem. Its purpose is to
break a larger task down so that each step can be carried out without creativity. An algorithm is a well ordered collection of unambiguous and effectively computable operations that produces a result. An algorithm is a precisely defined and ordered sequence of instructions that is guaranteed to solve a specific problem. Or an algorithm is a precise, systematic method for producing a specified result.
There are following important characteristics and properties for a well defined algorithm. These are Unambiguous It means each step should be clear. Deterministic Unique action specified by each step. Feasible It means the problem can be solved by algorithm. Finite Algorithm comes to an end.

In a simple language an algorithm Is a procedure or formula for solving a problem. It is a well defined
rule or procedure for carrying out some specified task. A task usually involves solving a problem of a computer or a real life problem like: The structure of algorithm consist of a sequence of steps it Make a choice between alternative actions it Repeat some actions and it can be broken down into simpler sub-algorithms for example suppose we have to write an algorithm for the addition of two numbers and display the result of operation then we will write it in simple understandable English language by the following way: Write an algorithm that will display numbers from 1 to 100. Algorithm: 1. Start. 2. Take a variable say A and assign it value 0. 3. Increment the value of A by one. 4. Print the value of A. 5. Repeat steps 2 to 3 till the value of A becomes 100. 6. Stop. Or we can write the above algorithm in short and meaningful way by the following method.

1. Start. 2. A=0. 3. A=A+1. 4. Print A. 5. If A < 100 then Repeat steps 3 and 4. 6. Stop.

Write an algorithm that will display all the even numbers from 1 to 1000. 1. Start 2. A=0 3. A=A+2. 4. Print A. 5. If A < 1000 then Repeat steps 3 and 4. 6. Stop. Write an algorithm that will display the table of any number. Algorithm: 1. Start 2. Input Num. 3. Count=0 4. Count =Count + 1 5. Table = Num * Count. 6. Print Table 7. If Count < 10 then Repeat steps 4 to 6. 8. Stop.

Write an algorithm that will display the addition of any two numbers.

Algorithm Steps for the addition of two numbers 1. Start. 2. Input A, B. 3. Sum=A+B 4. Print Sum. 5. Stop.

Write an algorithm for the summation of following series. 1+2+3+4+..+n. Algorithm Steps 1. Start. 2. Sum=0, Count=0 3. Input N. 4. Count = Count + 1. 5. Sum = Sum + Count. 6. If count < N Then Repeat steps 4 and 5. 7. Print Sum 8. Stop.

Flowchart: Flow chart is very important tool for developing algorithm and program . It is
pictorial representation of step by step solution of a problem.Programmer often uses it as a program planning tool for visually organizing step necessary to solve a problem. It uses boxes of different shapes that denotes different type of instruction. While making a flow chart a programmer need not to pay attention on the elements of the programming language ,he has to pay attention to the logic of solution to the problem whereas, the term algorithm refers to the logic. it is step by step description how to arrive at the solution to the problem. Algorithm is defined as sequence of instruction that when executed in the specified sequence the desired results are obtained. The set of rules that define how a particular problem can be solved in finite number of steps is known as algorithm. A good algorithm help us to create a good program A Flowchart is a

diagram that uses graphic symbols to depict the nature and flow of the steps in a process. Another name for this tool is "flow diagram."

Start or end of the program

Computational steps or processing function of a program

Input or output operation

Decision making and branching

Connector or joining of two parts of program

To solve a problem in simplest and better way we use algorithm and flowchart so first we will write an algorithm then we will make a flow chart for that problem.

Algorithm Steps for the addition of two numbers 1. Initialize sum=0 2. Read two numbers say A and B from input 3. Add A and B and store in sum i.e. sum=A+B 4. Display the result on output Flowchart for the addition of two numbers

In the above flowchart at first we have used ellipse for starting and ending that will always be used in every flowchart, than we have used a rectangular box depicting initialization, and than parallelogram to read or input the numbers, than rectangular box for processing or the summation, than again weve used parallelogram to print the sum. Now we will create the flowchart and write algorithm for the addition of ten numbers.
Initialization: sum=0, count=0

Read next number: num Add num to sum (sum=sum+num) Increment count (count=count+1)

If count = 10 then o else Print sum Exit Goto Step 2 Goto Step 5

As we will move towards programming construct like decision, control, iteration we will be able to make more flowcharts.

Potrebbero piacerti anche