C Language Chapter 1
C Language Chapter 1
ALGORITHM
Introduction to Algorithm
Every programming language has its own construction or instructions to understand. The
most popular technique used to get a plan for the solution of a given problem after analyzing in
multiple dimensions is an algorithm.
An algorithm consist of set of explicit unambiguous, finite steps, which takes input and
produce output definitely in a finite time.
Step1: Start
Step3: Stop.
Factors of an Algorithm
1. Input
2. Output
3. Definiteness.
4. Finiteness.
5. Effectiveness.
Definiteness: The algorithm should definitely find the solution for the given problem.
Effectiveness: The efficient one that find the solution for a given problem than remaining
solutions.
Step1: Start
Step3: Stop.
Step1: Start
Step2: Input two values into the variables ‘a’ and ‘b’ from the keyboard.
Step3: Find the addition of ‘a’ and ‘b’ i.e., a+b and assign the resultant value to the variable ‘c’
Step5: Stop
Step1: Start
Step3: Before swapping print the values of ‘a’ and ‘b’.(For example a=10 and b=20).
Step4: Assign the value of ‘a’ to the variable ‘temp’ i.e., temp=a.
Step7: After swapping print the values of ‘a’ and ’b’.(In this a=20 and b=10).
Step8: Stop.
Top-Down Approach
The One of the programming approach that has proven to be most productive is called
top-down approach or top-down decomposition. Top-down decomposition is the process of
breaking the overall procedure or task into component parts (modules) and then subdivides each
component module until the lowest level of detail has been reached. It is called top-down design
or top-down decomposition since we start "at the top" with a general problem and design specific
solutions to its sub problems. In order to obtain an effective solution for the main problem, it is
desirable that the sub problems (subprograms) should be independent of each other. Then each
sub-problem can be solved and tested by itself. This is shown in below
Using this method, a complex problem is separated into simpler parts, which can be
programmed easily.
The payroll system of a company can contain the following modules or tasks
• Master file
• Earnings
• Deductions
• Taxing
• Net earning
• Print reports
The tasks given above can be represented in a hierarchical chart as shown below.
Identifying and diagramming the relationship between modules in this fashion allows
programmers to focus on the overall organization and logic of the program.
It is the set of principles that enable a problem to be solved by breaking it down into
manageable parts, step-by-step from the overall problem specification.
Step-wise Refinement
Every refinement step implies some design decisions. It is important that the programmer
is aware of the underlying criteria.