Sie sind auf Seite 1von 3

Algorithm: A process or set of rules to be followed in calculations or other problem-solving operations, by a computer.

In general, an algorithm can be described as a procedure to solve a problem. Characteristics of an Algorithm: Well-ordered: The steps are in a clear order Unambiguous: The operations described are understood by a user without further simplification.(clear and with out any confusion).

Method for Developing an Algorithm: Define the problem: State the problem you are trying to solve in clear and concise terms. List the inputs (information needed to solve the problem) and the outputs (what the algorithm will produce as a result) Describe the steps needed to convert or manipulate the inputs to produce the outputs. Test the algorithm: choose data sets and verify that your algorithm works! Example of Algorithm: To establish a telephonic communication between two subscribers the following steps are to be followed. Step-1: Dial the phone number Step-2: Phone rings at the called party Step-3 :caller waits for response Step-4 :called party picks up the phone Step-5 :conversation begins between them Structured Approach: Each algorithm has following three features: Sequence Selection Repetition Sequence structure: The sequence structure is the mechanism where one statement is executed after another. Selection Structure: The selection structure is the mechanism where statements can executed or skipped depending on whether a condition evaluates to TRUE or FALSE.

There are three selection structures in C: 1. IF 2. IF ELSE 3. SWITCH Example: If the number is busy then you have to dial phone number again.(in our example) Repetition Structure: The repetition structure is the mechanism where statements can be executed repeatedly until a condition evaluates to TRUE or FALSE. There are three repetition structures in C: 1. WHILE 2. DO WHILE 3. FOR Example: While(not connected) { Dial number; } Algorithm v/s program: algorithm is a step by step outline for describing how to solve a problem. Program is an implemented coding of a solution to a problem based on the algorithm. Algorithm example: Example-1 //Sum of two numbers Step-1:read two numbers A,B Step-2 :Add two numbers Step-3:Store the result in c Step-4 print c Example-2 //write an algorithm to compare two numbers and print the result Step-1 Read two numbers Step-2 if A > B then print A is greater than B Step-3 if B > A then print B is greater than A Step-4 if A=B then print Both are equal Flowcharts: A graphical tool that diagrammatically depicts the steps and structure of an algorithm or program. The following are some guidelines in flowcharting: a.In drawing a proper flowchart, all necessary requirements should be listed out in logical order. b.The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart.

c.The usual direction of the flow of a procedure or system is from left to right or top to bottom. d.Only one flow line should come out from a process symbol. or e.Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol. f.Only one flow line is used in conjunction with terminal symbol. h.If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication. i.Ensure that the flowchart has a logical start and finish. j.It is useful to test the validity of the flowchart by passing through it with a simple test data. Problem 1: Write an algorithm and draw the flowchart for finding the average of two numbers Algorithm: Steps: 1. input x 2. input y 3. sum = x + y 4. average = sum /2 5. output average

Das könnte Ihnen auch gefallen