Compilers
Definition: compiler is a translator which translates high level
programming language into machine understandable format.
Algorithm: An Algorithm is a step-by-step procedure to solve a
given problem.Characteristics of an Algorithm:
1. Finiteness: An algorithm terminates after a fixed number of steps.
2. Definiteness: Each step of the algorithm is precisely defined, i.e., the
actions to be carried out should be specified unambiguously.
3. Effectiveness: All the operations used in the algorithm are basic
(division, multiplication, comparison, etc.) and can be performed
exactly in a fixed duration of time.
4. Input: An algorithm has certain precise inputs, i.e. quantities.
5. Output: An algorithm has one or more outputs, that is, the results
of operations which have a specified relation to the inputs.
Exercises:
1. Write an algorithm to swap two numbers without using temporary
variable.
2. Write an algorithm to find roots of a quadratic equation.
3. Write an algorithm to find largest of three numbers
4. Write an algorithm to find sum of first N numbers
5. Write an algorithm to find factorial of a given number.
6. Write an algorithm to generate first N Fibonacci series values.
Flowchart: Flowchart is a graphical representation of an algorithm. The
pictorialrepresentation of the algorithm is called flowchart.
A flowchart is a picture, which shows the sequence in which data are read,
Computingis performed, decisions are made and results are obtained. It
makes use of the basic operations in programming. All symbols are
,connected among themselves to indicate the flow of information and
processing.
The symbols which are used in flowchart are
i) Terminal: The oval represents any terminal point in a program and
generally containssuch words as BEGIN, START, END or STOP.
ii) Input/Output: The parallelogram represents the Input/Output
function i.e. makingdata available for processing (input) or recording of
the processed information (output).
iii) Process: The rectangle represents the processing operation. A process
changes ormoves data. An assignment is normally represented by this
symbol.
iv) Flow direction: Lines or arrows represent the flow direction
function – the flowof control. Normal flow direction is from left to right
or from top to bottom.
vi) Decision making symbol: The diamond represents a decision or
, switching type ofoperations that determines which of the alternative
paths is to be followed.
vii) Connector: The circle represents a function in a flow line.
Exercises
1. Write an algorithm to swap two numbers without using temporary
variable.
2. Write an algorithm to find roots of a quadratic equation.
3. Write an algorithm to find largest of three numbers
4. Write an algorithm to find sum of first N numbers
5. Write an algorithm to find factorial of a given number.
6. Write an algorithm to generate first N Fibonacci series values.
PSEUDO CODE
A Pseudocode allows the programmer to represent the implementation of an
algorithm.
A Pseudo code is an informal way of programming description that does not
require any strict programming language syntax or underlying technology
considerations.
Advantages of Pseudocode
1. Improves the readability.
2. Acts as a bridge between the algorithm and program.
3. The main goal of a pseudo code is to explain what exactly each line of a
program should do, hence making the code construction phase easier
for the programmer.
Example: Consider the following source code example:
, int n = 10
for( i=0;i<n;i++)
printf(n);
The above source code is converted into a pseudo-code to understand in a
better way.
The value ten is assigned to the variable n.
For value = zero to less than a number.
Display the numbers.
BRIEF HISTORY OF C
1. The C programming language is a structure-oriented programming language,
developed at Bell Laboratories in 1972 by Dennis Ritchie.
2. C programming language features were derived from an earlier language
called “B” (Basic Combined Programming Language – BCPL)
3. C language was invented for implementing UNIX operating system.
4. In 1978, Dennis Ritchie and Brian Kernighan published the first edition
“The C Programming Language” and is commonly known as K&R C.
5. In 1983, the American National Standards Institute (ANSI) established a
committee to provide a modern, comprehensive definition of C. The
resulting definition, the ANSI standard, or “ANSI C”, was completed late
1988.
6. Many of C’s ideas & principles were derived from the earlier language B,
thereby naming this new language “C”.
CHARACTERISTICS OF C
● ‘C’ is a structured programming language i.e., a C program can be
divided into multiple blocks where each block represents a function.
● ‘C’ language is suitable for developing both application software as
well as system software.
● It has a wide variety of derived datatypes like arrays, structures,
pointers and unions apart from fundamental data types like integers,
floating point numbers and characters. This makes the language