Solving a Problem
In order to solve a problem
Understand the problem clearly Gather the relevant information
Problem Definition
Understanding the problem thoroughly in terms of the requirements. Capability to extract a set of well defined tasks, to obtain the desired output. If the problem is not properly interpreted then we can not obtain the desired results.
Elementary Programming with C/Session 1/ 6 of 26
Analysis
The given problem must be analyzed before it is solved.
We should specify the operations (Arithmetic & logical) to be performed on them and checking the suitability in terms of memory & execution time
Design
Design of problems specifies the tools and techniques used to solve the problem. Design of techniques involves three ways 1.Algorithm 2 Flowchart 3.Pseudocode.
Algorithm
Algorithm is defined as a step by step procedure to solve a particular problem It consists of set of statement, and each statement must be well defined to perform a specific operation for required result. The word algorithm is named after the famous ninth century Arabic author and mathematician, Abu Jafar Mohammed Ibn Musa Al Khowarizmi
The last term of the name took different Pronunciations over the period such as Alkhowarism, Algorism & finally it became Algorithm.
Characteristic of algorithm
Input Output
Effectiveness
Elementary Programming with C/Session 1/ 11 of 26
Each & every algorithm is characterized by the following five characteristics 1.Input : It may accept zero or more inputs. 2.Output: It should produce at least one output(result) 3. Definiteness : Each instruction must be clear, welldefined and precise. There should not be any ambiguity. 4. Finiteness : It should be a sequence of finite instructions. That is, it should end after a fixed time. It should not enter an infinite loop. 5. Effectiveness : This means that operation must be simple and carried out in a finite time at one or more levels of complexity. It should be effective whenever traced manually for the results.
Notations of algorithm
While writing algorithms the following notations are considered 1.Name of the algorithm : It specifies the problem to be solved. 2Step Number : Identification tag of an instruction and it is an unsigned positive integer. 3.Explanatory Comment : It follows the step number and describes the operation. It should be written within a pair of invaded codes. 4.Termination : It specifies the end of the algorithm It is generally a STOP statement & the last instruction in the algorithm.
Elementary Programming with C/Session 1/ 13 of 26
Example
Algorithm to compute the area of circle
Algorithm: Area of circle Step1 : Read radius
Flowchart
The flow chart can be defined as a visual or graphical or diagrammatic representations of an algorithm. It is referred to as blue print of an algorithm Flow charts make use of geometrical figures, to specify particular operation.
The flow chart is easy to understand and analyze the problem. It is an useful aid for programmers and system analysts. It is machine independent. They can be used for any type of problems. Flow charts are classified into two types. They are 1.Program flowcharts. 2.System flowcharts.
Pseudocode
The pseudo code is neither an algorithm nor a program.
It consists of an English like statements which perform the specific operations. It is defined for an algorithm. It doesn't use any graphical representation.
In pseudo code, the program is represented in terms of words and phrases, but the syntax of program is not strictly followed. Advantages: Easy to read Easy to understand Easy to modify
Coding
A program is a set of instructions to solve a particular problem by the computer and actual process of writing a program is called coding. Coding is done by using a specific language, to execute a program.
Debugging
The process of detecting and correcting errors is known as debugging. Three types of error :1. Syntax errors 2. Logical errors 3. Run-time errors
SYNTAX ERRORS
This type of errors are the result of violation of rules of programming language. It is easy to debug these error. On encountering these error , system will displays error message with line number.
LOGICAL ERROR
These error occur during coding process. While coding the program ,programmer must process the correct operation. During this error the program will execute but produce some unwanted error. We can eliminate it by tracing it again.
RUN-TIME ERROR
These error occur due to unclear instructions. For ex. An infinite loop in program which causes no output. On encountering these error , system will displays error messageThese are also occur due to device errors, improper sequencing of constructs, errors in system software, incorrect data input, etcThe computer will print the error message. Some of the runtime errors are Divide by zero, Null pointer assignment & Data overflow
TESTING
The process of running the program to test the correctness of outputs of a problem is called testing. The program is tested by executing with different sets of data. Logical errors are the outcome this process.
Documentation
While writing programs, it is a good
programming practice to make a brief explanatory note on the program or program segments. This explanatory note is called a comment. It explains how the program works and how to interact with it. Thus, it helps other programmers to understand the program.
1.
2.
There are two types documentation. They are Internal documentation : This documentation is a comment statement within a program. It describes the function of the program or segments. These statements are not translated to machine language. Translator simply discard these statements External documentation : This documentation is an executable statement in a program. It may be a message to the user to respond to the program requirement. This is accomplished using output statements. It makes the program more attractive and interactive.