Showing posts with label Logic. Show all posts
Showing posts with label Logic. Show all posts

Thursday, 16 August 2012

Errors in C

Errors (also known as bugs) are common while writing a program. The errors should be detected and removed, or else, the whole set of statements of a program will simply produce wrong result. Errors can be detected only while running the program.

In C errors are of 3 types - Syntax Error , Logical Error and Run-time Error .

  • Syntax Error : These are generally typing error of the statements that are not according to the grammatical rules or syntax of the language. 
  • Syntax error will definitely occur and the program will not compile if semicolon (separator) is not placed at the end of the statement.
  • Logical Error : It occurs due to entering logically incorrect statement in the program.
  • If an addition program is instructed to do subtraction, it will compile, but produce a wrong output. This is logical Error.
  • Run - time Error : A program free of syntax and logical errors, may not produce result due to run - time errors, which usually occur due to the following reasons : 
  • Statements instructing to divide a number by zero.
  • Statements instructing to find logarithm of a negative number. 
  • Statements instructing to find the square root of a negative number. 


Wednesday, 15 August 2012

Logic Building

Programming Logic
To run an error - free program, the logic of the program should be very clear. A programmer is said to be good, if his/her programming logic is lucid. To make the conception clear, the following methods are highly necessary before starting a program.

Algorithm
Before solving a problem with the help of a computer, it is essential to plan the solution is a step - by - step manner. A set of instructions to solve a problem is termed as an algorithm. Algorithms can be expressed in different ways, like, by drawing flowcharts using specific symbols or writing the solution as a set of instructions in our native language/English. It is easy to understand and can be implemented in any programming language.

Two distinct kind of algorithms :
1. Pseudocode
2. Flowchart

Pseudocode
Pseudocode allows a programmer to represent logic in his/her native language. It is easier to convert the program logic developed using pseudocode to any high-level language code. Following points have to be taken care into consideration while developing the logic of a program using pseudocode.
  • Pseudocode must be language - independent.
  • Indent lines make pseudocode easier to read and understand.
  • Pseudocode are meant to concentrate on logic of the program rather than language syntax. 
Flowchart
A flowchart is symbolic representation of the step - by - step solution of a given problem. Flow-charting is a method of charting the flow of the steps that the computer follows. A flowchart is a type of map showing which steps in a process precede or follow others. It indicates the flow of the entire process, the sequence of the data input, operations, decisions, results and other relevant information, pertaining to a particular problem.

Symbols used in Flow chart