0% found this document useful (0 votes)
15 views

PSC-UNIT-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

PSC-UNIT-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Course Code Course Title L T P C

10210CS101 Problem Solving using C 3 0 0 3

Course Category: Foundation

a. Preamble :
Modern world aims to replace computer for human works. Any real world problem can be
solved using computers most effectively. The areas like weather forecast, defence,
construction, medical, business, marketing, education, entertainment makes use of the
computer for more than three decades. To solve the real world problem through
programming in an efficient manner, basic knowledge of computing is required. This
course provides adequate knowledge to solve the problems in respective domains. C is a
language which begins from scratch and it has foundational concepts on which today
concepts stand on. C is the mother of all programming languages since most dominant
languages and system softwareare written in C.

b. Prerequisite Courses:
Higher Secondary Level Mathematics

c. Course Educational Objectives :


Learners are exposed to
 The fundamentals of Computer, Hardware and Software, Representation of
Solution to problem
 The basics of C programming and its elements
 Array and Functions
 Structure, Pointer and Dynamic memory allocation
 File concept and graphics in C

d. Course Outcomes :
Upon the successful completion of the course, students will be able to:
Knowledge Level
CO (Based on revised
Course Outcomes
No’s Bloom’s
Taxonomy)
Describe the basics of computer, problem solving technique and K2
CO1 represent the algorithm, flow chart and pseudocode for the given
problem.
Design and develop C program to evaluate simple arithmetic and K2
CO2 logical problems
Develop C programs using arrays and practice to decompose the K3
CO3
problem into functions
Demonstrate the usage of structures and understand the concept of K3
CO4 pointer
Perform I/O operations in files and learn the basics of graphics in K3
CO5 C
E. Course Content:
Theory

UNIT 1 INTRODUCTION TO COMPUTERS 9


Introduction of computer, Overview of operating systems, compilers, interpreters and
programming languages, Number system, Memory, Variables, Values, Instructions, Programs
Problem Solving Techniques- Programming Logic - Sequence, Selection and Repetition -Flow
chart-Algorithm - Pseudocode.
UNIT 2 INTRODUCTION TO C 9
Overview of C Tokens - Data Types, Operators and Expressions evaluation of expressions,
precedence of operators and associativity, Statements: Declarations, Input-Output Statements –
formatted I/O statements, Compound statements, Selection Statements. Conditions, Enumerated
Data Types, Logical operators – Precedences, Repetitive statements: While construct, Do-while
Construct, For construct.
UNIT 3 ARRAYS AND FUNCTIONS 9
Arrays (1-D, 2-D)- static and dynamic array allocation, Character arrays and Strings Searching
and Sorting Algorithms, Built in functions - User defined functions and its elements - definition of
functions - return values and their types - function calls - function declaration - types of functions,
scope, visibility of variables in functions Functions (including built in libraries), Parameter
passing in functions, call by value, Passing arrays to functions: idea of call by reference Passing
arrays to functions, string handling function- Recursive function.
UNIT 4 STRUCTURES AND POINTERS 9
Structures and unions - accessing structure members arrays within structures, arrays of structures,
structures within structures,passing structures as function arguments. Type defining
structures,Pointers: Pointer variables. Declaring and dereferencing pointer variables. Pointer
Arithmetic. Examples. Accessing arrays through pointers. Pointers and strings. Pointers to
Functions (call by value and call by reference -Pointers to Arrays, Pointers to Structures, Dynamic
memory allocation.
UNIT 5 FILE HANDLING AND GRAPHICS 9
File Management in C – Input / Output Operations on Files - Sequential and Random Access
(Text and Binary files) The ‘C’ Pre-processor- Macro Substitution - Command Line Arguments,
Introduction to C Graphics

Text Books:

1. E. Balagurusamy, - Computing Fundamentals and C Programming, 8th Edition Tata


McGraw-Hill, 2019.
Reference Books:

1. R.G.Dromey, How to Solve by Computer, Pearson Education, Inc, Reprint 2009.


2. ReemaThareja, -Fundamentals of Computing & C Programming‖ Oxford University
Press2012.
3. YashavantKanetkar- Let Us C Solutions-12th Edition|| BPB Publication,2014
4. Byron Gottfried - Programming with C|| Schaum's Outline,2000
5. Dr.E.Kannan, Prof.E.Kamalanaban, Dr.P.Visu, Dr.S.Koteeswaran- Computing
Fundamentals & Programming in C‖, First Edition, CENGAGE Learning, 2015.

Online resources
1. https://www.learn-c.org/
2. https://www.cprogramming.com/tutorial/c-tutorial.html
3. https://www.tutorialspoint.com/cprogramming/index.htm
4. https://computer.howstuffworks.com/c1.htm
5. http://www.tutorialspoint.com/computer_fundamentals/
6. https://www.programiz.com/c-programming
UNIT-1

UNIT 1 INTRODUCTION TO COMPUTERS


Introduction of computer, Overview of operating systems, compilers, interpreters and
programming languages, Number system, Memory, Variables, Values, Instructions, Programs
Problem Solving Techniques- Programming Logic - Sequence, Selection and Repetition -Flow
chart-Algorithm - Pseudocode.

1.1 Introduction to Computer


A computer is an electronic machine that processes raw data to give information as output.
An electronic device that accepts data as input, and transforms it under the influence of a set of
special instructions called Programs, to produce the desired output (referred to as Information

Fig 1. Basic parts of Computer

A computer is described as an electronic device because; it is made up of electronic


components and uses electric energy (such as electricity) to operate.
A computer has an internal memory, which stores data & instructions temporarily awaiting
processing, and even holds the intermediate result (information) before it is communicated to the
recipients through the Output devices.
It works on the data using the instructions issued, means that, the computer cannot do any
useful job on its own. It can only work as per the set of instructions issued.
A computer will accept data in one form and produce it in another form. The data is
normally held within the computer as it is being processed.
Program:
A computer Program is a set of related instructions written in the language of the computer
& is used to make the computer perform a specific task (or, to direct the computer on what to do).
A set of related instructions which specify how the data is to be processed.
A set of instructions used to guide a computer through a process.
Data: Is a collection of raw facts, figures or instructions that do not have much meaning to the
user.¬ Data may be in form of numbers, alphabets/letters or symbols, and can be processed to
produce information.
Types Of Data.
There are two types/forms of data:
a). Digital (discrete) data:
Digital data is discrete in nature. It must be represented in form of numbers, alphabets or
symbols for it to be processed by a computer. Digital data is obtained by counting.
b). Analogue (continuous) data:
Analogue data is continuous in nature. It must be represented in physical nature in order to
be processed by the computer. ¬ Analogue data is obtained by measurement. E.g. Pressure,
Temperature, Humidity, Lengths or currents, etc.¬ The output is in form of smooth graphs from
which the data can be read.
Data Processing:
It is the process of collecting all items of data together & converting them into
information.
Processing refers to the way the data is manipulated (or handled) to turn it into information.
The processing may involve calculation, comparison or any other logic to produce the
required result. The processing of the data usually results in some meaningful information being
produced.
Information: is the data which has been refined, summarized & manipulated in the way you want
it, or into a more meaningful form for decision-making. ¬ The information must be accurate,
timely, complete and relevant.

Basic Characteristics of Computer :


Computer is an electronic device which is used to store the data, as per given instructions it gives
results quickly and accurately.
Data : Data is a raw material of information.
Characteristics of Computer

Fig 2. Characteristics of Computer

1.Speed:- As you know computer can work very fast. It takes only few seconds for calculations
that we take hours to complete. You will be surprised to know that computer can perform millions
(1,000,000) of instructions and even more per second. Therefore, we determine the speed of
computer in terms of microsecond
2. Accuracy:- The degree of accuracy of computer is very high and every calculation is
performed with the same accuracy. The accuracy level is 7. determined on the basis of design of
computer. The errors in computer are due to human and inaccurate data.
3. Diligence - A computer is free from tiredness, lack of concentration, fatigue, etc. It can work
for hours without creating any error. If millions of calculations are to be performed, a computer
will perform every calculation with the same accuracy. Due to this capability it overpowers
human being in routine type of work.
4. Versatility:- It means the capacity to perform completely different type of work. You may use
your computer to prepare payroll slips. Next moment you may use it for inventory management or
to prepare electric bills.
5. Power of Remembering - Computer has the power of storing any amount of information or
data. Any information can be stored and recalled as long as you require it, for any numbers of
years. It depends entirely upon you how much data you want to store in a computer and when to
lose or retrieve these data.
6. No IQ - Computer is a dumb machine and it cannot do any work without instruction from the
user. It performs the instructions at tremendous speed and with accuracy. It is you to decide what
you want to do and in what sequence. So a computer cannot take its own decision as you can.
7. Storage:- The Computer has an in-built memory where it can store a large amount of data. You
can also store data in secondary storage devices such as floppies, which can be kept outside your
computer and can be carried to other computers.

Application of Computers
Education : Getting the right kind of information is a major challenge as is getting information to
make sense. College students spend an average of 5-6 hours a week on the internet. Research
shows that computers can significantly enhance performance in learning. This offers a variety of
internet and video-based online courses.

Fig 3. Application of Computer

Health and Medicine : Computer technology is radically changing the tools of medicine. All
medical information can now be digitized. Software is now able to computer the risk of a disease.
Mental health researchers are using computers to screen troubled teenagers in need of
psychotherapy. A patient paralyzed by a stroke has received an implant that allows
communication between his brain and a computer; as a result, he can move a cursor across a
screen by brainpower and convey simple messages.
Science: Scientists have long been users of it. A new adventure among scientists is the idea of a
“collaboratory”, an internet based collaborative laboratory, in which researchers all over the world
can work easily together even at a distance. An example is space physics where space physicists
are allowed to band together to measure the earth‟s ionosphere from instruments on four parts of
the world.
Business: Business clearly see the interest as a way to enhance productivity and competitiveness.
Some areas of business that are undergoing rapid changes are sales and marketing, retailing,
banking, stock trading, etc. Sales representatives not only need to be better educated and more
knowledgeable about their customer‟s businesses, but also must be comfortable with computer
technology. The internet has become a popular marketing tool. The world of cybercash has come
to banking – not only smart cards but internet banking, electronic deposit, bill paying, online
stock and bond trading, etc.
Government: Various departments of the Government use computer for their planning, control
and law enforcement activities. To name a few – Traffic, Tourism, Information & Broadcasting,
Education, Aviation and many others. Defence: There are many uses computers in Defence such
as:
• Controlling UAV or unmanned air-crafts an example is Predator. If you have cable I would
recommend watching the shows “Future Weapons" and “Modern Marvels". The show future
weapon gives an entire hour to the predator.
• They are also used on Intercontinental Ballistic Missiles (ICBMs) that uses GPS and Computers
to help the missile get to the target.
• Computers are used to track incoming missiles and help slew weapons systems onto the
incoming target to destroy them.
Sports: In today's technologically growing society, computers are being used in nearly every
activity. Recording Information : Official statistics keepers and some scouts use computers to
record statistics, take notes and chat online while attending and working at a sports event.
Analyzing Movements : The best athletes pay close attention to detail. Computers can slow
recorded video and allow people to study their specific movements to try to improve their
tendencies and repair poor habits.

1.1.1 Types Of Computers or Classification of Computers


1. Super Computers
2. Main Frame Computers
3. Mini Computers
4. Micro Computers
Fig 4 Types of Computer
1. Super Computers are the most powerful computers in terms of speed of execution and large
storage capacity. NASA uses supercomputers to track and control space explorations. E.g.:-
CRAY Research :- CRAY-1 & CRAY-2, Fujitsu (VP2000), Hitachi (S820), NEC (SX20), PARAM
10000 by C-DAC, Most powerful Computer system - needs a large room
Minimum world length is 64 bits
CPU speed: 100 MIPS Equivalent to 4000 computers
High cost: 4 – 5 millions
Able to handle large amount of data
High power consumption
High precision Applications
In petroleum industry - to analyze volumes of seismic data which are gathered during oil seeking
explorations to identify areas where there is possibility of getting petroleum products inside the
earth.

2. Mainframe Computers Are next to supercomputers in terms of capacity. The mainframe


computers are multi terminal computers, which can be shared simultaneously by multiple
users. Unlike personal computers, mainframe computers offer time-sharing For example,
insurance companies use mainframe computers to process information about millions of its
policyholders.
E.g.:- IBM 3000 series, Burroughs B7900, Univac 1180, DEC
Able to process large amount of data at very high speed
Supports multi-user facility
Number of processors varies from one to six.
Cost: 3500 to many million dollars
Kept in air conditioned room to keep them cool
Supports many I/O and auxiliary storage devices
Supports network of terminals
Applications
Used to process large amount of data at very high speed such as in the case of Banks/ Insurance
Companies/ Hospitals/ Railways…which need online processing of large number of transactions
and requires massive data storage and processing capabilities
Used as controlling nodes in WANs (Wide Area Networks)
Used to mange large centralized databases
3. Minicomputers These computers are also known as midrange computers. These are
desk-sized machines and are used in medium scale applications. For example, production
departments use minicomputers to monitor various manufacturing processes and assembly line
operations.
E.g.:- Digital Equipments PDP 11/45 and VAX 11)
Perform better than micros
Large in size and costlier than micros
Designed to support more than one user at a time
Posses large storage capacities and operates at higher speed
Support faster peripheral devices like high speed printers
Applications
These computers are used when the volume of processing is large for e.g. Data processing for a
medium sized organization
Used to control and monitor production processes
To analyze results of experiments in laboratories
Used as servers in LANs (Local Area Networks)
4. Microcomputers As compared to supercomputers, mainframes and minicomputers,
microcomputers are the least powerful. It is having single processor but these are very widely
used and rapidly gaining in popularity. It comprises of a keyboard, mouse, monitor and system
unit. The system unit is also known as cabinet or chassis. It is the container that houses most of
the components such as motherboard, disk drives, ports, switch mode power supply and add-on
cards etc. The desktop computers are available in two models- horizontal model and tower model.

Applications
Used in the field of desktop publishing, accounting, statistical analysis, graphic designing,
investment analysis, project management, teaching, entertainment etc.,
The different models of microcomputers are given below:-
a) Personal computers:- The name PC was given by the IBM for its microcomputers. PCs are used
for word processing, spreadsheet calculations, database management etc.
b) Note book or Lap Top:- Very small in terms of size – can be folded and carried around –
Monitor is made up of LCD and the keyboard and system units are contained in a single box.
1.1.2 Generation Of Computers
The first electronic computer was designed and built at the University of Pennsylvania based on
vacuum tube technology. Vacuum tubes were used to perform logic operations and to store data.
Generations of computers has been divided into five according to the development of
technologies used to fabricate the processors, memories and I/O units.

1. I Generation : 1945 – 56
2. II Generation : 1956 – 63
3. III Generation : 1963 – 75
4. IV Generation : 1975 – 89
5. V Generation : 1989 to present

1) First Generation (1945 – 56):


Vacuum tubes were used – basic arithmetic operations took few milliseconds
Bulky
Consume more power with limited performance
High cost
Uses assembly language – to prepare programs. These were translated into machine level
language for execution.
Mercury delay line memories and Electrostatic memories were used
Fixed point arithmetic was used
100 to 1000 fold increase in speed relative to the earlier mechanical and relay based
electromechanical technology
Punched cards and paper tape were invented to feed programs and data and to get results.
Magnetic tape / magnetic drum were used as secondary memory
Mainly used for scientific computations.

Example:
ENIAC - Electronic Numerical Integrator And Calculator
EDSAC – Electronic Delay Storage Automatic Calculator
EDVAC – Electronic Discrete Variable Automatic Computer
UNIVAC – Universal Automatic Computer
IBM 701

2) Second Generation (1956 – 63):


Transistors were used in place of vacuum tubes. (invented at AT&T Bell lab in 1947)
Small in size
Lesser power consumption and better performance
Lower cost
Magnetic ferrite core memories were used as main memory which is a random access non-
volatile memory
Magnetic tapes and magnetic disks were used as secondary memory
Hardware for floating point arithmetic operations was developed.
Index registers were introduced which increased flexibility of programming.
High level languages such as FORTRAN, COBOL etc were used - Compilers were developed
to translate the high-level program into corresponding assembly language program which was
then translated into machine language.
1000 fold increase in speed.
Increasingly used in business, industry and commercial organizations for preparation of
payroll, inventory control, marketing, production planning, research, scientific & engineering
analysis and design etc.
Example:
Manufacturers – IBM 7030, Digital Data Corporation‟s PDP 1/5/8 Honeywell 400

3) Third Generation(1963 – 75):


ICs were used Small Scale Integration and Medium Scale Integration technology were
implemented in CPU,
I/O processors etc smaller & better performance
Comparatively lesser cost ,Faster processors. In the beginning magnetic core memories were
used. Later they were replaced by semiconductor memories (RAM & ROM)
Introduced microprogramming
Microprogramming, parallel processing (pipelining, multiprocessor system etc),multi
programming, multi-user system (time shared system) etc were introduced.
Operating system software were introduced (efficient sharing of a computer system by several
user programs)
Cache and virtual memories were introduced (Cache memory makes the main memory appear
faster than it really is. Virtual memory makes it appear larger)
High level languages were standardized by ANSI eg. ANSI FORTRAN, ANSI COBOL etc.,
Database management, multi-user application, online systems like closed loop process
control,airline reservation, interactive query systems, automatic industrial control etc emerged
during this period.
Example:
System 360 Mainframe from IBM, PDP-8 Mini Computer from Digital Equipment
Corporation.

4) Fourth Generation (1975 – 89):


Microprocessors were introduced as CPU– Complete processors and large section of main
memory could be implemented in a single chip
Tens of thousands of transistors can be placed in a single chip (VLSI design implemented)
CRT screen, laser & ink jet printers, scanners etc were developed.
Semiconductor memory chips were used as the main memory.
Secondary memory was composed of hard disks – Floppy disks & magnetic tapes were used
for backup memory
Parallelism, pipelining cache memory and virtual memory were applied in a better way
LAN and WANS were developed (where desktop work stations interconnected)
Introduced C language and Unix OS
Introduced Graphical User Interface
Less power consumption
High performance, lower cost and very compact
Much increase in the speed of operation
Example:
Intel‟s 8088,80286,80386,80486 .., Motorola‟s 68000, 68030, 68040, Apple II, CRAY I/2/X/MP
etc.,

5) Fifth Generation (1989 to present):


Generation number beyond IV, have been used occasionally to describe some current computer
system that have a dominant organizational or application driven feature.
Computers based on artificial intelligence are available
Computers use extensive parallel processing, multiple pipelines, multiple processors etc
Massive parallel machines and extensively distributed system connected by communication
networks fall in this category.
Introduced ULSI (Ultra Large Scale Integration) technology – Intel‟s Pentium 4
microprocessor
contains 55 million transistors millions of components on a single IC chip.
Superscalar processors, Vector processors, SIMD processors, 32 bit micro controllers and
embedded processors, Digital Signal Processors (DSP) etc have been developed.
Memory chips up to 1 GB, hard disk drives up to 180 GB and optical disks up to 27 GB are
available (still the capacity is increasing)
Object oriented language like JAVA suitable for internet programming has been developed.
Portable note book computers introduced
Storage technology advanced – large main memory and disk storage available
Introduced World Wide Web. (and other existing applications like e-mail, e Commerce, Virtual
libraries/Classrooms, multimedia applications etc.)
Example:
IBM notebooks, Pentium PCs-Pentium 1/2/3/4/Dual core/Quad core.. SUN work stations,
Origin 2000, PARAM 10000, IBM SP/2

1.1.3 Basic Computer Organization


The basic computer organization explains the way in which different units of computer are
interconnected with each other and controlled. Basic units of computer system are:
1) Input Unit
2) Central Processing Unit
3) Output Unit
Basic organization of computer is shown in Fig.4
Fig 5 Organization of Computer

1. Input Unit
An input unit is an electronic device, which is used to feed input data and control signals
to a computer.
Computers need data and instructions in order to solve any problem. We need to put the
data and instructions into the computers. The input unit consists of one or more input devices. All
input devices perform the following functions:
1. Accept data and instruction from the outside world.
2. Convert it to a form that the computer can understand.
3. Supply the converted data to the computer system for further processing
Input Devices
Following are the common input devices which are used in Computer Systems
 Keyboard
 Mouse
 Joy Stick
 Light pen
 Track Ball
 Scanner
 Graphic Tablet
 Microphone
 Magnetic Ink Card Reader (MICR)
 Optical Character Reader (OCR)
 Bar Code Reader
 Optical Mark Reader

Keyboard
Most common and very popular input device is keyboard. The keyboard helps in inputting
the data to the computer. The layout of the keyboard is like that of traditional typewriter, although
there are some additional keys provided for performing some additional functions.
Keyboards are of two sizes 84 keys or 101/102 keys, but now 104 keys or 108 keys
keyboard is also available for Windows and Internet.

Fig Key board

Mouse
Mouse is most popular Pointing device. It is a very famous cursor-control device. It is a
small palm size box with a round ball at its base which senses the movement of mouse and sends
corresponding signals to CPU on pressing the buttons. Generally it has two buttons called left and
right button and scroll bar is present at the mid. Mouse can be used to control the position of
cursor on screen, but it cannot be used to enter text into the computer.

Fig: Mouse
Light Pen
Light pen is a pointing device which is similar to a pen. It is used to select a displayed
menu item or draw pictures on the monitor screen. It consists of a photocell and an optical system
placed in a small tube.
When light pen's tip is moved over the monitor screen and pen button is pressed, its
photocell sensing element detects the screen location and sends the corresponding signal to the
CPU

Fig: Light Pen


Scanner
Scanner is an input device which works more like a photocopy machine. It is used when
some information is available on a paper and it is to be transferred to the hard disc of the
computer for further manipulation. Scanner captures images from the source which are then
converted into the digital form that can be stored on the disc. These images can be edited before
they are printed.
Fig: Scanner

Digitizer
Digitizer is an input device which converts analog information into a digital form.
Digitizer can convert a signal from the television camera into a series of numbers that could be
stored in a computer. They can be used by the computer to create a picture of whatever the
camera had been pointed at. Digitizer is also known as Tablet or Graphics Tablet because it
converts graphics and pictorial data into binary inputs. A graphic tablet as digitizer is used for
doing fine works of drawing and images manipulation applications

Fig: Digitizer

2. Central processing unit


It is the heart of the computer system. All operations are carried out in CPu only. In most
modern computers, a single IC does the following work
i) It performs all calculations
ii) It makes all decisions
iii) It controls and co-ordinates all units of the computer
The CPU is sub-divided into the following sub-system:
1. Control unit
2. Arithmetic and logical unit (ALU)
3. Memory unit
 Primary Storage
 Secondary storage
(i) Control unit
The control unit instructs the computer how to carry out program instructions. It directs
the flow of data between memory and arithmetic logical unit. It controls and coordinates the
entire computer system.
The control unit controls all other parts of the computer. The input unit does not know
when to receive data and where to put the data in the storage unit after receiving it. The control
unit gives the necessary instructions to the input unit, the control unit instructs the input unit
where to store the data after receiving it from user. In the same way, it controls the flow of data
and instructions from the storage unit to ALU. It also controls the flow of the results from the
ALU to the storage unit. The control unit also controls what should be sent to the output unit.

(ii) Arithmetic and logical unit


Arithmetic and logical unit performs all the arithmetic and logical operations, arithmetic
operations like addition, subtraction, multiplication and logical operations such as comparisons.
All calculations are performed in the arithmetic and logical unit (ALU) of the computer. ALU also
does comparisons and takes decision. Whenever any calculation has to be done, the control unit
transfers the required data from the storage unit to the ALU.
(iii) Memory unit
Memory unit is the part of computer which holds data for processing and other
information. The memory units of a computer are classified as 2 types:

1) Primary Memory

2)Secondary Memory

1) Primary Memory:
 Primary memory is also known as primary storage or main memory.
 Primary memory is computer memory that a processor or computer accesses first or directly.
 It hold the program being currently executed in the computer. The program that you want to
run on the computer is first transferred to the primary memory before it can run.
 This primary memory is temporarily store the data for processing by CPU.
 Each &ever information can process through any main memory.
 It is fast & expensive.
 As soon as a computer starts, primary memory loads all running applications, including the
base operating system (OS), user interface and any user-installed and running software utility.
 A program/application that is opened in primary memory interacts with the system processor
to perform all application-specific tasks.

Commonly used primary memories are,


1. RAM (Random Access Memory)
2. ROM (Read Only Memory)
Difference Between RAM and ROM

RAM ROM

Random Access Memory Read only memory

Volatile storage. Data is erased as soon as Non-volatile storage. Data remains stored even
power supply is turned off. after power supply has been turned off.

It allows Reading and Writing. It allows Reading only.

It is Temporary storage. It is Permanent storage.

RAM is expensive ROM is cheaper than RAM.

There are two types of RAM: Three types of ROM available:


1.SRAM (Static Random Access Memory) 1.PROM (Programmable ROM)
2. DRAM (Dynamic Random Access Memory). 2. EPROM (Erasable PROM)
3.EEPROM (Electrically EPROM).

Cache Memory

• Cache memory holds frequently requested data and instructions so that they are immediately
available to the CPU when needed.
• Cache memory is an extremely fast memory that acts as a buffer between RAM and the
CPU, which is placed between CPU and the main memory.
• Cache memory is used to reduce the average time to access data from the Main memory.
(iv) Secondary Memory
 The secondary storage represents the external storage devices that are connected to the
computer.
 It may store several programs, documents, database, etc.
 It is the permanent storage; the data stored in this storage will not be erased when the
power is lost. It is a non-volatile memory.
 The secondary memory is slower than the primary memory.
Example: Some of the commonly used secondary memory devices are Floppy disk, Hard disk
drive, Compact Disk (CD), Digital Video Disk (DVD).

3. Output unit
These devices used to get the response or result from the processor. Output unit is the
communication between the user and the computer. The output unit of a computer provides the
information and results of a computation to the outside world. It converts information into human-
readable form. It can be text, graphics, tactile, audio, and video.
Commonly used output devices are,
 Monitor
 Graphic Plotter
 Printer
 Speaker
 Headphone
 Projector
 Touchscreen
Fig: CRT Monitor

Fig: Flat –Panel Display Monitor


Printers
Printer is the most important output device, which is used to print information on paper.There are
two types of printers
Impact Printers Non-Impact Printers
Impact Printers
The printers that print the characters by striking against the ribbon and onto the paper are called
impact printers.
Characteristics of Impact Printers are following
 Very low consumable costs
 Impact printers are very noisy
 Useful for bulk printing due to low cost
 There is physical contact with the paper to produce an image
These printers are of two types
Character printers
Line printers
Character Printers:
Character Printers are printers which print one character at a time.
These are of further two types
Dot Matrix Printer (DMP)
Daisy Wheel
Dot Matrix Printer
In the market one of the most popular printer is Dot Matrix Printer because of their ease of
printing features and economical price. Each character printed is in form of pattern of Dot's and
head consists of a Matrix of Pins of size(5*7, 7*9, 9*7 or 9*9) which comes out to form a
character that is why it is called Dot Matrix Printer.
Advantages
 Inexpensive
 Widely Used
 Other language characters can be printed

Non-impact Printers
The printers that print the characters without striking against the ribbon and onto the paper are
called Non-impact Printers. These printers print a complete page at a time, also called as Page
Printers.
These printers are of two types
Laser Printers
Inkjet Printers
Characteristics of Non-impact Printers
 Faster than impact printers.
 They are not noisy.
 High quality.
 Support many fonts and different character size.
Laser Printers
These are non-impact page printers. They use laser lights to produces the dots needed to form the
characters to be printed on a page.
Advantages
 Very high speed.
 Very high quality output.
 Give good graphics quality.
 Support many fonts and different character size.
Disadvantage
 Expensive.
 Cannot be used to produce multiple copies of a document in a single printing .

1.2 Overview of operating systems


An operating system acts as an intermediary between the user of a computer and computer
hardware. The purpose of an operating system is to provide an environment in which a user can
execute programs conveniently and efficiently.
An operating system is software that manages computer hardware. The hardware must
provide appropriate mechanisms to ensure the correct operation of the computer system and to
prevent user programs from interfering with the proper operation of the system. A more common
definition is that the operating system is the one program running at all times on the computer
(usually called the kernel), with all else being application programs.
An operating system is concerned with the allocation of resources and services, such as
memory, processors, devices, and information. The operating system correspondingly includes
programs to manage these resources, such as a traffic controller, a scheduler, a memory
management module, I/O programs, and a file system.
Language Translators These are the programs which are used for converting the programs in
one language into machine language instructions, so that they can be excuted by the computer.
1) Compiler: It is a program which is used to convert the high level language programs into
machine language
2) Assembler: It is a program which is used to convert the assembly level language programs into
machine language
3) Interpreter: It is a program, it takes one statement of a high level language program, translates
it into machine language instruction and then immediately executes the resulting machine
language instruction and so on.
Interpreter Compiler
Translates program one statement at a time. Scans the entire program and translates it as a
whole into machine code
It takes less amount of time to analyze the It takes large amount of time to analyze the
source code but the overall execution time is source code but the overall execution time is
slower. comparatively faster
No intermediate object code is generated, Generates intermediate object code which
hence are memory efficient. further requires linking, hence requires more
memory
Continues translating the program until the It generates the error message only after
first error is met, in which case it stops. scanning the whole program. Hence
Hence debugging is easy. debugging is comparatively hard.
Programming language like Python, Ruby Programming language like C, C++ use
use interpreters. compilers.

1.3 Computer Languages


Language is the communication medium, the computer languages are used to
communicate with the computer. These are the communication media between the user and the
computer. The computer languages are formed with the group of instruction often called as
programs. The computer languages are divided as follows.

Fig 5 Computer Languages

1. Machine languages
The machine language is formed with the help of binary digits. This is also called as the
low level language. This language is the collection of instruction using binary digits 0’s and 1’s.
There are as named as the machine can directly understand the programs.
Advantages of machine language:
1. The computer can understand instruction immediately.
2. No translation is needed
Disadvantages of machine language:
1. Machine dependent
2. Writing a Programming is very difficult
3. Very difficult to find an error.
Example: add 4 and 9
0100
1001
_____________
1101
______________

2. Assembly Language
It was developed to overcome some of the many inconveniences of machine language.
This is another low level but a very important language in which operation codes and operands
are given in the form of alphanumeric symbols instead of 0’s and l’s. These alphanumeric symbols
will be known as mnemonic codes and can have maximum up to 5 letter combination e.g. ADD
for addition, SUB for subtraction, START, LABEL etc. Because of this feature it is also known as
‘Symbolic Programming Language’.
This language is also very difficult and needs a lot of practice to master it because very
small. English support is given to this language. The language mainly helps in compiler
orientations. The instructions of the Assembly language will also be converted to machine codes
by language translator to be executed by the computer.
Advantages of Assembly Language
i) It is easier to understand and use as compared to machine language.
ii) It is easy to locate and correct errors. iii) It is modified easily.
Disadvantages of Assembly Language
i) Like machine language it is also machine dependent.
ii) Since it is machine dependent therefore programmer should have the knowledge of the
hardware also
Example: addition of 4 and 9 Say A=4 B=9
MVI A move A value to Accumulator
ADD B add B with Accumulator
STA C Store Accumulator contents to C
HLT Halt the program.

3. High Level Languages


High level computer languages give formats close to English language and the purpose of
developing high level languages is to enable people to write programs easily and in their own
native language environment (English). High-level languages are basically symbolic languages
that use English words and/or mathematical symbols rather than mnemonic codes. Each
instruction in the high level language is translated into many machine language instructions thus
showing one-to-many translation.
These are categorized according to their use as
 Visual programming language.
 Object Oriented Programming Language.
 String and List Processing.
 Business Data Processing.
 Algebraic Formula-Type Processing.
 Types of High Level Languages.
Advantages of High Level Language
Following are the advantages of a high level language:
i) It is easier to learn.
ii) They require less time to write and easier to maintain.
iii) Problem oriented rather than 'machine' based
Disadvantages of High Level Language
i) A high-level language has to be translated into the machine language by a translator and
thus a price in computer time is paid.
ii) The object code generated by a translator might be inefficient Compared to an equivalent
assembly language program.

1.4 NUMBER SYSTEM


The number system or the numeral system is the system of naming or representing
numbers. It is defined as a system of writing to express numbers. It is the mathematical notation
for representing numbers of a given set by using digits or other symbols in a consistent manner. It
provides a unique representation of every number and represents the arithmetic and algebraic
structure of the figures. It also allows us to operate arithmetic operations like addition,
subtraction, multiplication and division.

The value of any digit in a number can be determined by:

 The digit
 Its position in the number
 The base of the number system

Types of Number Systems

There are various types of number systems in mathematics. The four most common number
system types are:

1. Decimal number system (Base- 10)


2. Binary number system (Base- 2)
3. Octal number system (Base-8)
4. Hexadecimal number system (Base- 16)
Different number system conversions are followed.
1. Decimal to binary
2. Decimal to octal
3. Decimal to Hexadecimal
4. Binary to decimal
5. Binary to octal
6. Binary to hexadecimal
7. Octal to decimal
8. Octal to binary
9. Octal to hexadecimal
10. Hexadecimal to binary
11. Hexadecimal to decimal
12. Hexadecimal to Octal
1. Conversions of Decimal to Binary- The method that is used for converting of decimals into
binary is known as the remainder method. We use the following steps in getting the binary
number
(a) Divide the decimal number by 2.
(b) Write the remainder (which is either 0 or 1) at the right most position.
(c) Repeat the process of dividing by 2 until the quotient is 0 and keep writing the
remainder after each step of division.
(d) Write the remainders in reverse order
Conversions of Decimal Fractions to Binary Fractions- For converting decimal fractions into
binary fractions, we use multiplication. Instead of looking for a remainder we look for an integer.
The following steps are used in getting the binary fractions-
(a) Multiply the decimal fraction by 2.
(b) If a non-zero integer is generated, record the non-zero integer otherwise record 0.
(c) Remove the non-zero integer and repeat the above steps till the fraction value
becomes 0.
(d) Write down the number according to the occurrence.
Example- Find the binary equivalent of (0.75)10.
Number (to be recorded)
0.75 × 2 = 1.50 1
0.50 × 2 = 1.00 1
Thus (0.75)10= (0.11)2.
Moreover, we can write (45.75)10= (101101.11)2.
Remark- If the conversion is not ended and still continuing; we write the approximation in 16
bits.
Example- Find the binary equivalent of (0.9)10.
Number (to be recorded)
0.9 × 2 = 1.8 1
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
Thus (0.9)10 = (0.111001100110011001)2.
2. Conversions of Binary to Decimal – In converting binary to decimal, we use the following
steps-
(a) Write the weight of each bit.
(b) Get the weighted value by multiplying the weighted position with the respective bit.
(c) Add all the weighted value to get the decimal number.
Example- Convert (101101)2 into decimal number system.

Conversions of Binary Fractions to Decimal Fractions – The conversions of binary fractions to


the decimal fractions is similar to conversion of binary numbers to decimal numbers. Here,
instead of a decimal point we have a binary point. The exponential expressions (or weight of the
bits) of each fractional placeholder is 2-1, 2-2………
Example- Convert (101101.11)2 into decimal number system.

Thus (101101.11)2= 32 + 0 + 8 + 4 + 0 + 1 + 0.5 + 0.25 = 45.75


3. Conversion of Decimal to Octal- In converting decimal to octal, we follow the same process
of converting decimal to binary. Instead of dividing the number by 2, we divide the number by 8.
Example- Convert (45)10 into octal number system.

Thus (45)10= (55)8.


Conversions of Decimal Fractions to Octal Fractions – We follow the same steps of
conversions of decimal fractions to binary fractions. Here we multiply the fraction by 8 instead of
2.
Example- Find the octal equivalent of (0.75)10.
Number (to be recorded)
0.75 × 8 = 6.00 6
Thus (0.75)10= (0.6)8.
And (45.75)10= (55.6)8.
4. Conversion of Decimal to Hexadecimal – We divide by 16 instead of 2 or 8. If the remainder
is in between 10 to 16, then the number is represented by A to F respectively.
Example- Convert (45)10 into hexadecimal.
Thus (45)10= (2D)16.
Conversions of Decimal Fractions to Hexadecimal Fractions – Here we multiply the fraction
by 16 instead of 2 or 8. If the non-zero integer is in between 10 to 16, then the number is
represented by A to F respectively.
Example- Find the hexadecimal equivalent of (0.75)10.
Number (to be recorded)
0.75 × 16 = 12.00 C (12 = C) Thus (0.75)10=
(0.C)16.
And (45.75)10= (2D.C)16.
5. Conversions of Octal to Decimal- We follow the same steps of conversion of binary to
decimal. The only difference is that here weight of nth bit is 8n-1 instead of 2n-1.
Example- Convert (55)8 into decimal number system.

Thus (55)8 = 40 + 5. = 45
Conversions of Octal Fractions to Decimal Fractions- The weight of the bit of the fraction
placeholder is 8-1, 8-2………. We follow the same steps of conversion of binary fractions to
decimal fractions.
Example- Convert (55.6)8 into decimal number system
Thus (55.6)8= 40 + 5 + 0.75 = 45.75
6. Conversions of Octal to Binary- We use the following steps in converting octal to binary-
(a) Convert each octal digit into 3-bit binary equivalent.
(b) Combine the 3-bit section by removing the spaces to get the binary number.
Example- Convert (55)8 into binary.

Conversions of Octal Fractions to Binary Fractions- We follow the same steps of conversion
of octal to binary.
Example- Convert (55.6)8 into binary
Octal 5 5 6
Number
Binary 101 101 110
Number
Thus (55.6)8 = (101101.11)2.
7.Conversions of Binary to Octal- We use the following steps in converting binary to octal-
(a) Break the number into 3-bit sections starting from LSB to MSB.
(b) If we do not have sufficient bits in grouping of 3-bits, we add zeros to the left of MSB so
that all the groups have proper 3-bit number.
(c) Write the 3-bit binary number to its octal equivalent.
Example- Convert (101101110)2 into octal.
Binary 101 101 110
Number
Octal Number 5 5 6

Thus (101101110)2 = (556)8.


Conversions of Binary Fractions to Octal Fractions- We use the following steps in converting
binary
fractions to octal fractions-
(d) Break the fraction into 3-bit sections starting from MSB to LSB.
(e) In order to get a complete grouping of 3 bits, we add trailing zeros in LSB.
(f) Write the 3-bit binary number to its octal equivalent.
Example- Convert (101101.11)2 into octal
Binary 101 101 110
Number
Octal Number 5 5 6

8. Conversions of Hexadecimal to Binary-We use the following steps-


(a) Convert each hexadecimal digit to its 4-bit binary equivalent.
(b) Combine all the binary numbers.
Example- Convert (2D)16 into binary.
Hexadecimal Number 2 D(=13)

Binary Number 0010 1101


Thus (2D)16 = (00101101)2= (101101)2.
Conversions of Hexadecimal Fractions to Binary Fractions -We use the same steps of
hexadecimal to binary conversion.
Example- Convert (2D.C)16 into binary.
Hexadecimal Number 2 D(=13) C(=12)
Binary Number 0010 1101 1100
Thus (2D)16 = (00101101.1100)2= (101101.11)2.
9. Conversions of Binary to Hexadecimal- We convert binary to hexadecimal in the similar
manner as we have converted binary to octal. The only difference is that here, we form the group
of 4 – bits.
Example- Convert (101101)2 into hexadecimal
Binary Number 0010 1101
Decimal Number 2 13
Hexadecimal Number 2 D
Thus (101101)2 = (2D)16.
Conversions of Binary Fractions to Hexadecimal Fractions - We convert binary fractions to
hexadecimal fractions in the similar manner as we have converted binary fractions to octal
fractions. The only difference is that here we form the group of 4 – bits
Example- Convert (101101.11)2 into hexadecimal
Binary Number 0010 1101 1100
Decimal Number 2 13 12
Hexadecimal Number 2 D C
Thus (101101.11)2 = (2D.C)16.
10. Conversions of Hexadecimal to Decimal- We do the conversion of hexadecimal to decimal
as we have done the conversion of binary to decimal. Here weight of nth bit is 16 n-1 instead of 2n-
1
.
Example- Convert (2D)16 into decimal.

Thus (2D)16= 32 + 13 = 45.


Conversions of Hexadecimal Fractions to Decimal Fractions- We do the conversion of
hexadecimal fractions to decimal fractions in the similar manner as we have done the conversion
of binary fractions to decimal fractions. Here weight of bit is 16 -1, 16-2…….
Example- Convert (2D.C)16 into decimal.

Thu
s (2D.C)16= 32 + 13 + 0.75 = 45.75.

11.Conversions of Octal to Hexadecimal- The conversion involves the following steps-


(a) Convert each octal digit to 3 –bit binary form.
(b) Combine all the 3-bit binary numbers.
(c) Group them in 4-bit binary form by starting from MSB to LSB.
(d) Convert these 4-bit blocks into their hexadecimal symbols.
Example- Convert (55)8 into hexadecimal.
12.Conversions of Hexadecimal to Octal- We convert each hexadecimal digit in binary.
Combine
all the binary numbers. Again group them into 3-bit form. Convert the 3-bit block in octal.
Example- Convert (2D)16 into octal.

Binary 101 101


Number
Octal Number 5 5

Thus (2D)16 = (55)8.


Conversions of Hexadecimal Fractions to Octal Fractions – We follow the same steps of
hexadecimal to octal conversion.
Example- Convert (2D.C)16 into octal.
1.5 Memory
Memory in a computer refers to the hardware devices used to store and retrieve data. There are
two main types of memory:

1. Primary Memory (RAM - Random Access Memory):


o This is volatile memory, meaning it loses its data when the power is turned off.
o It is used for storing data and instructions that the CPU needs while performing
tasks.
o It is faster than secondary memory but has limited storage capacity.
2. Secondary Memory:
o This is non-volatile memory, meaning it retains data even when the power is turned
off.
o It includes devices like hard drives, solid-state drives (SSD), and optical disks.
o It is used for long-term storage of data and programs.
o It has a larger storage capacity compared to primary memory but is slower.
Variables
Variables are symbolic names used in programming to represent data that can change. They act as
containers for storing data values. Variables have three main characteristics:
1. Name: The identifier used to refer to the variable.
2. Type: The kind of data the variable can hold (e.g., integer, float, string).
3. Value: The actual data stored in the variable.

Values
Values are the actual data or content that variables hold. They can be of various data types, such
as:
1. Integers: Whole numbers (e.g., 10, -3).
2. Floats: Numbers with decimal points (e.g., 3.14, -0.001).
3. Strings: Sequences of characters (e.g., "Hello, World!").
4. Booleans: True or False values.

Instructions:
Instructions are commands given to the computer to perform specific operations. These
can include arithmetic operations, data movement, and control operations. Instructions are written
in programming languages and are executed by the CPU.The instruction execution takes place in
the CPU registers.
The CPU reads (fetches) instructions (codes) from the memory one at a time, and executes
or performs the operation specified by this. Instruction fetch involves reading of an instruction
from a memory location to the CPU register.
Programs:
Programs are sets of instructions that are executed by a computer to perform specific
tasks. Programs are written in programming languages and can range from simple scripts to
complex applications. A program typically consists of multiple instructions that work together to
achieve a goal.
1.6 Problem Solving Techniques

1. Problem definition phase


2. Getting started on a problem
3. The use of specific examples
4. Similarities among problems
5. Working backwards from the solution
6. General problem solving strategies
1. Problem Definition Phase
• Understand the problem
• Work out what must be done rather than how to do it
• Lot of care must be taken in working our what must be done
Example
o Finding the square root
o Finding the greatest common divisor
• From the definition develop an algorithm
2. Getting started on a problem
· There may be many ways to solve the problem and also many solutions to most
problems.
· Have an idea of where to start the problem
· Try to understand the problem clearly and do not worry about implementation
· Develop implementation-independent solution
· Postpone coding
· Sooner you start coding your program the longer it is going to take
3. The use of specific examples
• Pick on a specific example of the general problem we are trying to solve
• Use some properties to try to get a solution for the problem
• Apply the mechanism to solve the problem
Example : Find out the maximum number from the given set of numbers
• Use some geometrical or schematic diagrams representing certain aspects of the problem
4. Similarities among problems
 See if there are any similarities between the current problem and other problems that we
have solved or we have seen solved
 Try to solve the problem independently

5. Working Backwards from the Solution


1. If we do not know where to start on a problem,
2. We can work backwards to the starting conditions
3. Whatever attempts that we make to get started on a problem write down the various steps and
explorations we made.
4. Once we have solved a problem we must remember the steps that we went about discovering
the solution
5. The most important one is practice
6. General Problem-Solving Strategies
a) Divide and Conquer
b) Dynamic Programming
c) Divide and Conquer:
It is defined as one large complex problem is divided into number of sub problems and finds the
solution. The sub problem solutions are combined to form the solution for large problem.
Example: MERGE SORT
d) Dynamic programming:
Dynamic programming is an algorithm that can be used when the solution to a problem
can be viewed as the result of a sequence of decisions.
Example: TRAVELLING SALESMAN PROBLEM
e) Backtracking: During the search if infeasible solution is sensed then backtrack to
previous node.
Example: Sudoku, 8-Queens Problem
f) Branch and Bound:
Branch- splitting procedure
Bound- computes upper and lower bounds
Example: Knapsack problem
g)Greedy method: Find the feasible solution from the set of solution for the given problem
Example: job scheduling

1.7. Programming Logic


Programming logic is the foundation of writing efficient and effective code. It involves
using logical thinking to solve problems, structure your program, and ensure it
Programming structures are broken down into three simple structures called

1. Sequence structure
2. Selection structure
3. Repetition structure

Programming Constructs: Sequence, Selection, and Repetition


Understanding sequence, selection, and repetition is fundamental to grasping how
programs control the flow of execution. These constructs are used in almost every programming
language to create structured and logical programs.
1. Sequence
The instructions are computed in sequence of actions that is completed in a specific order.

Sequence refers to the execution of code statements one after another in a specific order. This is
the simplest form of control structure where instructions are executed in the same order in which
they appear.

2. Selection
Selection involves making decisions based on conditions. It allows the program to choose
different paths of execution. The primary selection constructs are if, else if, else, and switch. The
if-else statement in C is used to perform the operations based on some specific condition. The
operations specified in if block are executed if and only if the given condition is true.
There are the following variants of if statement in C language.
If Statement
The if statement is used to check some given condition and perform some operations
depending upon the correctness of that condition. It is mostly used in the scenario where we need
to perform the different operations for the different conditions. The syntax of the if statement is
given below.
If-else Statement
The if-else statement is used to perform two operations for a single condition. The if-else
statement is an extension to the if statement using which, we can perform two different
operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness
of the condition. Here, we must notice that if and else block cannot be executed simultaneously.
Using if-else statement is always preferable since it always invokes an otherwise case with every
if condition. The syntax of the if-else statement is given below.

If else-if ladder Statement


The if-else-if ladder statement is an extension to the if-else statement. It is used in the
scenario where there are multiple cases to be performed for different conditions. In if-else-if
ladder statement, if a condition is true then the statements defined in the if block will be executed,
otherwise if some other condition is true then the statements defined in the else-if block will be
executed, at the last if none of the condition is true then the statements defined in the else block
will be executed. There are multiple else-if blocks possible. It is similar to the switch case
statement where the default is executed instead of else block if none of the cases is matched.

3. Repetition

• Repetition structures are used to repeat statements or blocks of code.


• The decision whether to repeat the code is based on the evaluation of a logical expression.
• If the expression is true, the code is executed. If false, the code is not executed.
The primary repetition constructs are for, while, and do-while loops.

While Loop

• A while loop is one of the most common types of loop.


• The main characteristic of a while loop is that it will repeat a set of instructions based on
a condition.
• As far as the loop returns a boolean value of TRUE, the code inside it will keep repeating.
• We use this kind of loop when we don't know the exact number of times a code needs to
be executed.


Do-WHILE Loop
• The statement given in the Do block are executed atleast once and after that repeatedly
executed until the given condition is true.
• The condition is always executed after the body of a loop. It is also called an exit-
controlled loop.
• At each instance of execution of block statements, the condition is checked.
• If the condition is true, then only block statement are executed; otherwise the repetition
structure is terminated.

for Loop
• The initial value is performed only once, then the condition tests and compares the counter
to a fixed value after each iteration, stopping the for loop when false is returned.
1.8. FLOWCHART
 A flowchart is the graphical representation of the flow of control and logic for solving a
problem. It is a pictorial representation of an algorithm.
 It is a generic tool that can be adapted for a wide variety of purposes, and can be used to
describe various processes, such as a manufacturing process, an administrative or service
process, or a project plan.

USE A FLOWCHART
 To develop understanding of how a process is done and study a process for improvement
 To communicate to others how a process is done
 When better communication is needed between people involved with the same process
and to document a process when planning a project.
More Flowchart symbols

Symbol Name Function

Document Symbol A printed document or report

Multiple Documents Represents multiple documents in


Symbol the process.

Manual Input Symbol Represents a step where a user is


prompted to enter information
manually

Preparation Symbol Represents a set-up to another step


in the process.

Connector Symbol Indicates that the flow continues


where a matching symbol
(containing the same
letter) has been placed

Or Symbol Indicates that the process flow


continues in more than two
branches

Indicates a point in the flowchart


Summoning Junction where multiple branches converge
back into a single process.
Symbol

Indicates a step where two or more


Merge Symbol sub lists or sub-processes become
one.
Indicates a step that orders
Collate Symbol information into a standard format.
Indicates a step that organizes a list
Sort Symbol of items into a sequence or sets
based on some predetermined
criteria.

Indicates a sequence of actions that


Subroutine Symbol perform a specific task embedded
within a larger process. This
sequence of actions could be
described in more detail on a
separate flowchart
Indicates a sequence of commands
Manual Loop Symbol that will continue to repeat until
stopped manually.

Loop Limit Symbol Indicates the point at which a


loop should stop
.

Delay Symbol Indicates a delay in the process

Data Storage or Stored Indicates a step where data gets


Data Symbol Stored

Indicates a step that displays


Database Symbol information.

Internal Storage Indicates that information was


Symbol stored in memory during a
program, used in software
design flowcharts.

Indicates a step that displays


Display Symbol information.
FLOWCHART FOR DECISION MAKING STATEMENTS:
A simple flow chart showing the symbols for decision making statements(Simple IF):

1. ALGORITHM & FLOWCHART TO FIND THE AREA OF A CIRCLE:


Algorithm:
Step 1: Start
Step 2: Read the value of radius.
Step 3: Calculate the area and circumference of a circle using the formula.
A=3.14*r*r;
C=2*3.14*r;
Step 4: Print the values.
Step 5: Stop.
Flowchart

2. ALGORITHM & FLOWCHART TO FIND THE GIVEN NUMBER IS EVEN OR ODD.


Algorithm:
Step 1: Start.
Step 2: Read the value of a number.
Step 3: Check the given number by using if (n%2==0)
Step 4: if its remainder is zero, Print it is even number.
Step 5: If its remainder is one, Print it is odd number.
Step 6: Stop
Flowchart
3. ALGORITHM AND FLOWCHART TO PRINT THE NUMBERS FROM 1 to 10.
Algorithm:
Step 1:Start.
Step 2: Initialize the value of i by 1.
Step 3: Repeat the step 4 until (i<=10), then go to step 5.
Step 4: Print the value of i.
Step 5: Stop.

Flowchart

1.9 ALGORITHM
It is defined as a sequence of instructions designed in such a way that if the instructions
are executed in the specified sequence, the desired results will be obtained. The algorithm should
precise and unambiguous in practice and the results should obtain after a finite number of steps.
An algorithm is defined if any problem whose solution can be expressed in a list of executable
instruction.
Characteristics of algorithms
In order to qualify algorithms is a sequence of instructions, they must possess the following
characteristics:
i) In the algorithms, each and every instruction should be precise.
ii) Each and every instruction should be unambiguous
iii) Ensure that the algorithm will ultimately terminate.
iv) The algorithm should be written in sequence.
v) It looks like normal English
vi) The desired result should be obtained only after the algorithm terminates
Representation of algorithms
The algorithms can be represented in several ways. Generally the programmers follows one of the
following ways to represent an algorithms:
i) Normal English
ii) Flowchart
iii) Pseudo code
iv) Decision table
v) Program
A sample algorithm
Write an algorithm to calculate and print the total number of students selected in various group,
using the following criteria. In a school there are 100 student appeared for examination. Based
upon the student marks who secure greater than 70% as first class, greater than 60% as second
class, and greater than 50% as third class and remaining are fail.
Algorithm
Step 1: Start the program
Step 2: Read number of students, name of the student, marks.
Step 3: calculate the total marks obtained by each student.
Step 4: check student mark is greater than 70 or not. If greater than 70 then “first class”.
Step 5: check student mark is greater than 60 and less than 70or not. If so then, “second class”.
Step 6: check student mark is greater than 50 and less than 60 or not. If so then, “third class”.
Step 7: print the result of the student with their names and marks.
Step 8: Stop the program
1.10 PSEUDOCODE
 Pseudocode is a simplified, informal way of representing the logic of a program using
plain language.
 It is used to describe the steps that are to be performed for solving a problem (i.e.,) flow of
a program without worrying about syntax details specific to any programming language.
 It uses short phrases to write code for programs before you actually create it in a specific
language.
Characteristics of Pseudocode
 Simplicity: Easy to read and understand.
 Language-agnostic: Not tied to any specific programming language.
 Clarity: Clearly represents the logic and structure of the algorithm.
Basic Constructs in Pseudocode
• Pseudocode will be enclosed by START (or BEGIN) and STOP (or END).
• To accept data from user, generally used statements are INPUT, READ, GET or OBTAIN.
• To display result or any message, generally used statements are PRINT, DISPLAY, or
WRITE.
• Generally used keywords are capitalized while preparing pseudocode.
• Pseudocode should be concise so ignore unnecessary details.
1. Sequence: Execution of instructions one after another.
2. Selection: Decision-making using IF-THEN-ELSE, END IF , CASE, ELSE IF.
3. Repetition: Looping constructs like FOR, END FOR, WHILE, END WHILE , REPEAT –
UNTIL.
Example: 1 Pseudocode to add two numbers.
BEGIN
Get the value from the user(a,b)
c=a+b
print c
END
Example: 2 Pseudocode to find square root of a number.
BEGIN
READ num
result=SQRT(num)
DISPLAY result
END

Example: 3 Pseudocode to find area of the circle.


BEGIN
READ radius
area=3.14*radius*radius
DISPLAY area
END

Example: 4 Pseudocode to find the given number is positive or negative.


BEGIN
GET the value from the user (num)
If num>0
DISPLAY “number is positive”
ELSE
DISPLAY “Number is a negative”
END IF
END

Example: 5 Pseudocode to find the given number is Even or Odd.


BEGIN
READ num
IF num%2==0
DISPLAY “number is even”
ELSE
DISPLAY “Number is a odd”
END IF
END
Example: 6 Pseudocode to find sum of first n numbers (1+2+…+n).
BEGIN
READ n
SET sum=0, i=1
WHILE i<=n
sum=sum+i
i=i+1
END WHILE
PRINT sum
END

Example: 7 Pseudocode to find sum of all odd numbers from 1 to 100.


BEGIN
SET i=1, sum=0
WHILE i<=100
sum=sum+i
i=i+2
END WHILE
PRINT sum
END

Examples for different programming structures:


1. Sequence Structure :
Example : Compute sum of two integers
Algorithm:

1. Start.
2. Read numbers a and b.
3. Calculate the sum of a and b. sum=a+b
4. Print the value of sum.
5. Stop
Pseudocode:
BEGIN
DECLARE variables A, B, and sum as INTEGER
READ A, B
COMPUTE
sum = A + B
PRINT sum
END

Flowchart:

2. Selection Structure:
Example: Check whether the given number is even or odd.
Algorithm

1. Start
2. Read an integer number from the user.
3. Check if number is divisible by 2.
4. If number % 2 == 0 (i.e., the remainder when number is divided by 2 is 0), then number is
even.
5. Otherwise, number is odd.
6. Print whether the number is even or odd.
7. End
Pseudocode:
BEGIN
READ number
IF (number % 2 == 0) THEN
PRINT “number is even."
ELSE
PRINT “number is odd."
END IF
END

Flowchart:

3. Repetition Structure:
Example: Print the numbers from 1 to 10.Algorithm:

1. Start
2. Initialize the variable i to 1.
3. Repeat the following steps 5 & 6 while i is less than or equal to 10 then go to step 7.
4. Print the value of i.
5. Increment i by 1.
6. End
Pseudocode:
BEGIN
FOR i = 1 TO 10 DO
PRINT i
END FOR
END

Flowchart:

You might also like