You are on page 1of 65

Unit 1

Introduction to Programming

Dr. Nivedita Palia


Unit -1
Computer
 The word computer derived from the
word “compute”, which means, “to
calculate”
 Initially, a computer is developed to
perform arithmetic operations at high
speed
 Nowadays, a computer is mainly work as
data processor because it can store,
process, and retrieve data whenever
desired
Data
 It can be either numerical , non-numerical
or mixture of them
 Example :
• Covid-19 data
• Image data
• AQI
• UIDAI
Data Processing
The activity of processing data using a computer is called
data processing
Data

Data Gathering (from different Sources)

Merge Data

Process Data

Information
Data is raw material used as input and information is
processed data obtained as output of data processing
Characteristics of Computers
1) Automatic: After instructing computer what job to do and how
to do it work automatically without human interventions until it
finished the assigned work.

2) Speed: Computer can perform data processing jobs very fast,


usually measured in microseconds (10-6), nanoseconds (10-9), and
even picoseconds (10-12). It can perform billion (106),even
trillion(109 ) , simple arithmetic operations per second.

3) Accuracy: Accuracy of a computer is consistently high. It perform


every calculation with same accuracy. Errors are mainly occur due
to human rather than technological error. Computer errors caused
due to incorrect input data or unreliable programs are often
referred to as Garbage-In-Garbage-Out (GIGO) .
4) Diligence: Computer is free from monotony, tiredness, and
lack of concentration. It can continuously work for hours
without creating any error and with same accuracy.

5) Versatility: Computer is capable of performing almost any


task, if the task can be reduced to a finite series of logical steps

6) Power of Remembering: Computer can store huge amount


of information and recall any amount of information because
of its secondary storage capability. It forgets or losses certain
information only when it is asked to do so
7) No I.Q.: It cannot take its own decision. It possesses no
intelligence. It has to be instructed what to do and in which
order.

8) No Feelings: It cannot make judgments based on feelings


and instincts. Their judgment is based on the instructions
given to them in the form of programs that are written by
us (human beings)
The Five Basic Operations of a Computer System
 Inputting. The process of entering data and
instructions into the computer system
 Storing. Saving data and instructions to make
them readily available for initial or additional
processing whenever required
 Processing. Performing arithmetic operations
(add, subtract, multiply, divide, etc.) or logical
operations (comparisons like equal to, less than,
greater than, etc.) on data to convert them into
useful information
 Outputting. The process of producing useful
information or results for the user such as a
printed report or visual display

 Controlling. Directing the manner and sequence in


which all of the above operations are performed
Basic Organization of a Computer System
Input Unit
1. It accepts (or reads) instructions and data
from outside world in the form that
depends upon the input device used.
2. It converts these instructions and data in
computer acceptable form. Input interface
transforms input signal into binary form
3. It supplies the converted instructions and
data to the computer system for further
processing
Output Unit
1. It accepts the results produced by the
computer, which are in binary coded form
and hence, cannot be easily understood by
us
2. It converts these coded results to human
acceptable (readable) form using output
interfaces
3. It supplies the converted results to outside
world
Storage Unit
The storage unit of a computer system hold
(or stores) the following:
1. Data and instructions required for
processing (received from input devices)
2. Intermediate results of processing for
ongoing processing
3. Final results of processing, before they are
released to an output device
Two Types of Storage
 Primary Storage (Main Memory)
 Used to hold running program instructions
 Used to hold data, intermediate results of
processing, and results of ongoing process
 CPU can access directly
 Fast in operation
 Small Capacity
 Expensive
 Volatile (looses data on power dissipation)
 Secondary storage (Auxiliary storage)
 Used to hold stored program instructions
 Used to hold data, and information of stored
jobs
 Slower than primary storage
 Large Capacity
 Cheaper than primary storage
 Retains data even without power (Non –
Volatile)
Central Processing Unit (CPU)

 It is the brain of a computer system


 It controls the operations of all other units
of a computer system
Arithmetic Logic Unit (ALU)
Arithmetic Logic Unit of a computer system is
the place where the actual executions of
instructions take place during processing
operation
Control Unit (CU)
•Manages and coordinated the operations of
all other components of the computer system
•Obtains instructions from a program stored
in main memory, interprets the instructions,
and issue signals causing other units of the
system to execute .
Programming Languages
• It consist of a set of vocabulary and grammatical
rules to express the computations and tasks that the
computer has to perform
• Categories
Loader : the loader software is used to load and re-locate the executable program in
the main memory. It assign storage space to the program into the main memory.
Introduction to C
Structured language
High level languages
Machine independent
Developed by Dennis Ritchie at the AT &T’s
Bell laboratories in 1972
History
year language developer

1960 ALGOL International Group

1967 BCPL ( Basic Combined programming Matrin Richard


language)

1970 B Ken Thompson

1972 Traditional C Dennis Ritchie

1978 K&RC Kernighan and Ritchie

1989 ANSI ( American National Standard Institute) ANSI Committee


C
1990 ANSI/ISO C ISO ( International
Standard Organization)
1999 C99 Standardization Committee
Features of C
 It is a robust language with the capabilities of assembly language
and features of high level language. ( write any complex program)
 It is suitable for writing system software and business packages
also.
 Programs written in ‘C’ are efficient and fast. (Because of variety of
data types and powerful operators)
 Case-Sensitive
 Highly Portable. (related to OS)
 Well suited for structured programming.(Blocks)
 Ability to extend itself. (Addition to C library)
Software Development Life Cycle
Purpose of Program Planning
 To write a correct program, a programmer must write
each and every instruction in the correct sequence
 Logic (instruction sequence) of a program can be very
complex
 Hence, programs must be planned before they are
written to ensure program instructions are:
 Appropriate for the problem
 In the correct sequence
System Design phase
 It requires 3 steps
Algorithm
Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output. Algorithms are generally
created independent of underlying languages, i.e. an algorithm can be
implemented in more than one programming language.
Characteristics of an Algorithm

Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one
meaning.
Input − An algorithm should have 0 or more well-defined inputs.
Output − An algorithm should have 1 or more well-defined outputs, and should
match the desired output.
Finiteness − Algorithms must terminate after a finite number of steps.
Feasibility − Should be feasible with the available resources.
Independent − An algorithm should have step-by-step directions, which should be
independent of any programming code.
Algorithm
Design an algorithm to add two numbers and display the result.
Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of step 4 to c
Step 6 − print c
Step 7 − STOP
Algorithm
Algorithm Questions
1) Find the sum of first five integers and its Average.
2) Convert a given temp in F to C (c=5/9 *(F-32))
3) To find the area of the right angle triangle
4) To find Simple Interest when principal, rate of interest and
Time given
5) To check whether a number is prime or not
6) To find roots of quadratic equation
7) Print the sum for first 50 natural numbers
8) Print factorial of number.
9) Write an algorithm to evaluate
51+52+… +510
Efficiency of Algorithm
Space complexity of an algorithm represents the amount of
memory space required by the algorithm in its life cycle.

Time complexity of an algorithm represents the amount of time


required by the algorithm to run to completion.
Flowchart
 Flowchart is a pictorial representation of an algorithm
 Uses symbols (boxes of different shapes) that have standardized
meanings to denote different types of instructions
 Actual instructions are written within the boxes
 Boxes are connected by solid lines having arrow marks to
indicate the exact sequence in which the instructions are to be
executed
 Process of drawing a flowchart for an algorithm is called
flowcharting
Basic Flowchart Symbols
Examples of Decision Symbol
Examples of Decision Symbol
Control structure of flowchart
Sample Flowchart
Flowchart to multiply two number
Flowchart to find largest of three number
Flowchart to find sum of first 100 integer
Flowcharting Rules
 First chart the main line of logic, then incorporate detail
 Maintain a consistent level of detail for a given flowchart
 Do not chart every detail of the program. A reader who is
interested in greater details can refer to the program itself
 Words in the flowchart symbols should be common statements
and easy to understand
Flowcharting Rules
 Be consistent in using names and variables in the flowchart
 Go from left to right and top to bottom in constructing
flowcharts
 Keep the flowchart as simple as possible. Crossing of flow lines
should be avoided as far as practicable
 If a new flowcharting page is needed, it is recommended that
the flowchart be broken at an input or output point.
 Properly labeled connectors should be used to link the portions
of the flowchart on different pages
Advantages of Flowchart
 Better Communication
 Proper program documentation
 Efficient coding
 Systematic debugging
 Systematic testing
Limitations of Flowchart
 Flowcharts are very time consuming and laborious to draw
(especially for large complex programs)
 Redrawing a flowchart for incorporating changes/ modifications
is a tedious task
 There are no standards determining the amount of detail that
should be included in a flowchart
Pseudo-code
 A program planning tool where program logic is written in an
ordinary natural language using a structure that resembles
computer instructions
 “ Pseudo” means imitation or false and “ Code” refers to the
instructions written in a programming language. Hence, pseudo
code is an imitation of actual computer instructions
 Because it emphasizes the design of the program, pseudo-code
is also called Program Design Language (PDL)
Basic Logic (Control) Structures
Any program logic can be expressed by using only following three
simple logic structures:
1. Sequence logic,
2. Selection logic, and
3. Iteration (or looping) logic
Programs structured by using only these three logic structures are
called structured programs, and the technique of writing such
programs is known as structured programming
Sequence Logic
Selection Logic
 Also known as decision logic, it is used for making decisions
 Three popularly used selection logic structures are
1. IF…THEN…ELSE
2. IF…THEN
3. CASE
Selection Logic (IF…THEN…ELSE
Structure)
Selection Logic (IF…THEN Structure)
Selection Logic (CASE Structure)
Iteration (or Looping) Logic
 Used to produce loops in program logic when one or more
instructions may be executed several times depending on some
conditions
 Two popularly used iteration logic structures are
1. DO…WHILE
2. REPEAT…UNTIL
Iteration (or Looping) Logic (DO…WHILE Structure)
Iteration (or Looping) Logic (REPEAT…UNTIL
Structure)
Control Structure of Pseudo code
Pseudo code Example
Advantages of Pseudo code
 Converting a pseudo code to a programming language is much
more easier than converting a flowchart to a programming
language
 As compared to a flowchart, it is easier to modify the pseudo
code of a program logic when program modifications are
necessary
 Writing of pseudo code involves much less time and effort than
drawing an equivalent flowchart as it has only a few rules to
follow
Limitations of Pseudo code
 In case of pseudo code, a graphic representation of program
logic is not available
 There are no standard rules to follow in using pseudo code
 Different programmers use their own style of writing pseudo
code and hence communication problem occurs due to lack of
standardization
 For a beginner, it is more difficult to follow the logic of or write
pseudo code, as compared to flowcharting
Difference between Pseudo code and flowchart
END

You might also like