Niranjan Sapkota 1
Programming
A computer is an electronic (not electric)
device that accepts data using some input
devices, performs certain operations on the
data according to certain prescribed
sequence of instructions (i.e. program) and
displays the result(s) of those operations on
output devices.
Programming → Developing computer
programs
Niranjan Sapkota 2
Definition
Language: A predefined set of syntax rules
and its meaning
Programming Language: A language in which
we write a computer program.
Program: A set of instructions written in a
programming language, that when executed,
causes the computer to behave in a
predetermined manner.
Niranjan Sapkota 3
Why Programming?
There are a no. of problems to be solved
using computer e.g. sometimes we have to
calculate simple interest when principal, time
and rate of interest is provided, and
sometimes we have to prepare mark sheet of
a student and calculate his percentage.
It is possible manually.
Programming just makes problem solving
specific and efficient.
Programming is for problem solving.
Niranjan Sapkota 4
Why Programming Languages?
A computer is a dummy machine without a
program.
Computer works on 1’s (on) and 0’s (off).
It is difficult to provide instructions to the computer
in terms of 1’s and 0’s.
Also a computer does not understand human
language.
Therefore a negotiation between human and
machine is the programming language.
A computer understands programs written in a
programming language through a translator and a
human understands writing programs in a
programming language by learning.
Niranjan Sapkota 5
Problem Solving with Computer
A program is needed to solve a particular
problem.
The program must be planned before coding
in a programming language so as to make
sure that instructions in the program are
appropriate and sufficient to solve the
problem, and are in the correct sequence.
Niranjan Sapkota 6
Problem Solving Steps
1) Problem Analysis
2) Algorithm Development
3) Flowcharting
4) Coding
5) Compilation & Execution
6) Debugging & Testing
7) Documentation
Niranjan Sapkota 7
Problem Analysis
This step is the process of becoming familiar
(by analyzing and understanding) the
problem that will be solved with a computer
program.
The program’s inputs, outputs, different ways
of solving problems, and its constraints,
should be known in advance.
Niranjan Sapkota 8
Algorithm Development
An algorithm is a step-by-step description of
the method to solve a problem.
Algorithm maintains sequences of computer
instructions required to solve a problem in
such a way that if the instructions are
executed in the specified sequence, the
desired result is obtained.
Niranjan Sapkota 9
Flowcharting
Flowchart is the graphical representation of
an algorithm using standard symbols.
Niranjan Sapkota 10
Coding
Coding is the act of transforming operations
in each box of the flowchart in terms of the
statements of the programming language.
Coding is done using a programming
language such as C.
The code/program developed using a
programming language is called source
code/program.
Niranjan Sapkota 11
Compilation and Execution
The process of changing high level language into
machine level language is known as compilation. It
is done by special software, known as compiler.
The compilation process tests the program whether
it contains syntax errors or not. If there are syntax
errors, compiler cannot compile the code.
After successful compilation, the program is linked
with other object programs needed for execution,
and then the program is loaded in the memory for
the purpose of execution and finally it is executed.
During execution, the program may ask for user
inputs and generates outputs after processing the
inputs.
Niranjan Sapkota 12
Debugging and Testing
Debugging is the discovery and correction of
programming errors.
Testing ensures that program performs the
required task correctly.
For testing process, test data are supplied to
the program and output is observed. If the
output is as expected, the program can be
considered error free.
Niranjan Sapkota 13
Program Documentation
Program documentation is description of the
program and its logic written to support
understanding the program.
Use Comments: Comments are a basic part of
program documentation (written in a
program). These comments are not compiled
while compilation.
Niranjan Sapkota 14
Structured Programming
C is called a structured programming
language because to solve a large problem, C
programming language divides the individual
small responsibilities to smaller modules
called functions or procedures.
Niranjan Sapkota 15
Basic Structure of a C program
1) Documentation Section
2) Link Section
3) Definition Section
4) Global Declaration Section
5) main() function section
{
Declaration Part
Executable Part
}
6) Subprogram Section // User Defined
Functions
Function 1
Function 2
…………
Function n
Note:- main() function is compulsory
Niranjan Sapkota 16