0% found this document useful (0 votes)
34 views77 pages

Unit I

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

Unit I

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

SYLLABUS – R2013

GE6151 COMPUTER PROGRAMMING LTP


C
3 0
03

UNIT I INTRODUCTION 8

Generation and Classification of Computers- Basic Organization of a Computer –


Number System – Binary – Decimal – Conversion – Problems. Need for logical
analysis and thinking – Algorithm – Pseudo code – Flow Chart.

UNIT II C PROGRAMMING BASICS 10

Problem formulation – Problem Solving - Introduction to ‘ C’ programming –


fundamentals – structure of a ‘C’ program – compilation and linking processes –
Constants, Variables – Data Types – Expressions using operators in ‘C’ –
Managing Input and Output operations – Decision Making and Branching –
Looping statements – solving simple scientific and statistical problems.

UNIT III ARRAYS AND STRINGS 9


Arrays – Initialization – Declaration – One dimensional and Two dimensional
arrays. String- String operations – String Arrays. Simple programs- sorting-
searching – matrix operations.

UNIT IV FUNCTIONS AND POINTERS


9

Function – definition of function – Declaration of function – Pass by value – Pass


by reference – Recursion – Pointers - Definition – Initialization – Pointers
arithmetic – Pointers and arrays- Example Problems.

UNIT V STRUCTURES AND UNIONS 9

Introduction – need for structure data type – structure definition – Structure


declaration – Structure within a structure - Union - Programs using structures and
Unions – Storage classes, Pre-processor directives.

TOTAL: 45
PERIODS
TEXTBOOKS:
1. Anita Goel and Ajay Mittal, “Computer Fundamentals and Programming in C”,
Dorling
Kindersley (India) Pvt. Ltd., Pearson Education in South Asia, 2011.
2. Pradip Dey, Manas Ghosh, “Fundamentals of Computing and Programming in
C”, First
Edition, Oxford University Press, 2009
3. Yashavant P. Kanetkar. “ Let Us C”, BPB Publications, 2011.

REFERENCES:

1. Byron S Gottfried, “Programming with C”, Schaum’s Outlines, Second Edition,


Tata McGraw- Hill, 2006.
2. Dromey R.G., “How to Solve it by Computer”, Pearson Education, Fourth
Reprint, 2007.
3. Kernighan,B.W and Ritchie,D.M, “The C Programming language”, Second
Edition, Pearson Education, 2006.
CHAPTER I

INTRODUCTION TO COMPUTERS

1.1 DEFINITION

 A computer is an electronic device that accepts raw data, processes it


according to the set of instruction and produces the desired result.
 A computer is a machine that manipulates data according to a set of
instruction.
 A computer is an electronic device that takes input from the user,
processes the given input and generates output.
 Computer is an electronic device which is capable of receiving information
(data) in a particular form and of performing a sequence of operations in
accordance with a predetermined but variable set of procedural
instructions (program) to produce a result in the form of information or
signals.

1.2 APPLICATION OF COMPUTER

Following list demonstrates various applications of computers in today's arena.

1.2.1 Education

The computer has provided a lot of facilities in the education system.

 The computer provides a tool in the education system known as CBE


(Computer Based Education).
 CBE involves control, delivery, and evaluation of learning.
 The computer education is rapidly increasing the graph of number of
computer students.
 There are number of methods in which educational institutions can use
computer to educate the students.
 It is used to prepare a database about performance of a student and
analysis is carried out on this basis.
1.2.2 Business

A computer has high speed of calculation, diligence, accuracy, reliability,


or versatility which made it an integrated part in all business organisations.

Computer is used in business organisations for:

 Payroll calculations
 Budgeting

 Sales analysis

 Financial forecasting

 Managing employees database

 Maintenance of stocks etc.

1.2.3 Banking
Today banking is almost totally dependent on computer.

Banks provide following facilities:

 Banks provide online accounting facility, which includes current balances,


deposits, overdrafts, interest charges, shares, and trustee records.

 ATM machines are making it even easier for customers to deal with banks.

1.2.4 Insurance

Insurance companies are keeping all records up-to-date with the help of
computers. The insurance companies, finance houses and stock broking firms
are widely using computers for their concerns.

Insurance companies are maintaining a database of all clients with information


showing

 procedure to continue with policies


 starting date of the policies

 next due instalment of a policy

 maturity date

 interests due

 survival benefits

 bonus

1.2.5 Marketing
In marketing, uses of computer are following:

 Advertising - With computers, advertising professionals create art and


graphics, write and revise copy, and print and disseminate ads with the
goal of selling more products.

 At Home Shopping - Home shopping has been made possible through


use of computerised catalogues that provide access to product
information and permit direct entry of orders to be filled by the
customers.

1.2.6 Health Care

Computers have become important part in hospitals, labs, and


dispensaries. The computers are being used in hospitals to keep the record of
patients and medicines. It is also used in scanning and diagnosing different
diseases. ECG, EEG, Ultrasounds and CT Scans etc., are also done by
computerised machines.

Some major fields of health care in which computers are used are:
 Diagnostic System - Computers are used to collect data and identify
cause of illness.

 Lab-diagnostic System - All tests can be done and reports are prepared
by computer.

 Patient Monitoring System - These are used to check patient's signs


for abnormality such as in Cardiac Arrest, ECG etc.

 Pharmacy Information System - Computer checks Drug-Labels, Expiry


dates, harmful drug’s side effects etc.

 Surgery: Nowadays, computers are also used in performing surgery.

1.2.7 Engineering Design

Computers are widely used in Engineering purpose.

One of major areas is CAD (Computer aided design). That provides creation and
modification of images. Some fields are:

 Structural Engineering - Requires stress and strain analysis for design


of Ships, Buildings, Budgets, Airplanes etc.

 Industrial Engineering - Computers deal with design, implementation


and improvement of integrated systems of people, materials and
equipments.

 Architectural Engineering - Computers help in planning towns,


designing buildings, determining a range of buildings on a site using both
2D and 3D drawings.

1.2.8 Military
Computers are largely used in defence. Modern tanks, missiles, weapons etc.
Military also employs computerised control systems. Some military areas where
a computer has been used are:

 Missile Control
 Military Communication

 Military Operation and Planning

 Smart Weapons

1.2.9 Communication

Communication means to convey a message, an idea, a picture or speech that


is received and understood clearly and correctly by the person for whom it is
meant for. Some main areas in this category are:

 E-mail
 Chatting
 Usenet

 FTP

 Telnet

 Video-conferencing

1.2.10 Government

Computers play an important role in government. Some major fields in this


category are:

 Budgets
 Sales tax department

 Income tax department

 Male/Female ratio

 Computerization of voters lists

 Computerization of driving licensing system

 Computerization of PAN card

 Weather forecasting
1.3 OVERVIEW OF COMPUTER

Computers are combination of 2 major things

 Hardware
 Software

1.3.1 HARDWARE

Computer hardware is the physical parts or components of


a computer, such as the monitor, mouse, keyboard, computer data
storage, hard disk drive (HDD), system unit (graphic cards, sound cards,
memory, motherboard and chips), and so on, all of which are physical
objects that can be touched (that is, they are tangible). Computer
hardware is a visible component of the computer that enables the
computer hardware to function properly. It is the frame work on which the
computer software operates.

1.3.2 Various components of computer

1. CPU 2.Monitor 6.Speaker

3.

Keyboard

4.Mouse 5.Printer

i. Central Processing Unit (CPU) or Processor

CPU is the processor of the computer that is responsible for controlling


and executing instructions in the computer. It is considered as the most
important component of the computer. It is considered as “Brain of the
Computer”. A central processing unit (CPU) is the electronic circuitry within
a computer that carries out the instructions of a computer program by
performing the basic arithmetic, logical, control and input/output operations
specified by the instructions.

ii. Monitor

Monitor is a screen, which displays information to the user in visual form.


It is an output device of the computer system. A monitor or a display is
an electronic visual display for computers. The monitor comprises the display
device, circuitry and an enclosure. The display device in modern monitors is
typically a thin film transistor liquid crystal display (TFT-LCD) thin panel, while
older monitors used a cathode ray tube (CRT) about as deep as the screen size.

iii. Keyboard and Mouse

Keyboard and mouse are input devices, which are used to get input from
the user. A keyboard is a typewriter-style device, which uses an arrangement of
buttons or keys, to act as mechanical levers or electronic switches. Following the
decline of punch cards and paper tape, interaction via teleprinter-style
keyboards became the main input device for computers. A mouse is a pointing
device that detects two-dimensional motion relative to a surface. This motion is
typically translated into the motion of a pointer on a display, which allows for fine
control of a graphical user interface.

iv. Other hardware devices

There are various components of computer which are used for ideal
purposes. Some of the computer devices are
1. Printer
2. Speaker
3. DVD
4. Floppy Disk etc

1.3.3 SOFTWARE

A set of instructions/programs that can be executed sequentially in called


as Software. Software is generic term for an organized collection of computer
data and instruction. It is responsible for controlling, integrating and managing
the hardware components of a computer and for accomplishing specific task.
There are two types of Software.
i. System Software
ii. Application Software

i. System Software

System softwares are inbuilt software to boot/start the system. User


cannot work the computer without system softwares. These are mandatory to
start and work the computer.

Example: Operating System, Compiler, Linker, Loader etc

ii. Application Software


These softwares are optional and can be used along with system software.
User can run the computer without application software. The application
softwares are used for specific purpose. It helps the users to achieve their needs
and work faster.

Example: Games, Tally, VLC media player, CAD etc. There are thousands of
applications available to help the user to perform the desired tasks.

1.3.4 BASIC OPERATIONS OF COMPUTER

The computers have five basic operations to carry out any specified task.

i. Input: It is the process of capturing the information or raw data from the user.
ii. Process: It is the transformation process of converting input into output.
iii. Output: It is the result or outcome of the process.
iv. Storing: It is the process of saving the data or information or instruction,
which can be retrieved whenever it is required
v. Controlling: It is the process of directing the sequence in which all the
operations are to be performed.

1.4 CHARACTERISTICS OF COMPUTER

The characteristics of a computer are:

i. Speed
ii. Accuracy
iii. Versatility
iv. Diligence
v. Storage
vi. Reliability
vii. Resource sharing

i. Speed

Computer is a fast electronic device that can perform large and complex
problems in few seconds. Computers process data at fast rate, i.e., millions of
instructions per second. Speed of the computer is calculated in MHz (Mega
Hertz). Computer s work at very high speed and are much faster than humans.

Hertz  Unit defined as the number of cycles per second.


MHz  One million cycles per second.

ii. Accuracy

Accuracy means correctness. Computers operate at very high degree of


accuracy. Accuracy means results without any error. A modern computer
performs millions of operations in one second without any error. Computers are
capable of doing only the instruction given to it, hence faulty instructions or
input may lead to faulty results. This is called as GIGO (Garbage In Garbage Out).

iii. Versatility
Computers are versatile in nature used for many purpose. Computers
perform multiple tasks simultaneously. For example: User can type letter, browse
internet, play music, can print a document etc at same time.

iv. Diligence

Computer is a machine; it does not suffer with tiredness and lack of


concentration. Computers perform millionth operation with the same accuracy
and speed as the first calculation.

v. Storage

A computer can store a large amount of data permanently it has a built-


in memory where it can store any type of data, text, graphic, pictures, audio
and video files, etc. The storage capacity of the computer is increasing rapidly.
Secondary storage devices are also used for the data storage, they store the
data for which the user wants to retrieve these data for future us. Storage area
of a computer is generally divided into two categories.
 Main Memory
o Main memory is inbuilt memory in the computer; usually it is
relatively small and can hold only certain amount of
information.
o Example: RAM, ROM
 Secondary Storage
o It is external storage memory. Size of the secondary storage
varies from 1 GB to 30 GB in real time.
o Example: Magnetic Tapes, Floppy disk, CD, Pen Drive etc

Computer storage is measured in terms of Bytes. One bit is either 0 or 1.

1 Byte  8 bit
1 KB  1024 bytes
1 MB  1024 KB
1 GB  1024 MB
1 TB  1024 GB

KB = Kilo Byte
MB = Mega Byte
GB = Giga Byte
TB = Tera Byte

vi. Reliability

Reliability is the measurement of performance of a computer. Computers


have built-in diagnostic capabilities, which help in continuous monitoring of the
system. i.e., Fault Recovery.

vii. Resource Sharing

In the initial stages of development, computers used to be isolated


machines. But today’s computers can be connected together as network to share
the information or data in one computer to another computer. Number of
computer can share a single device i.e., Printer. Apart from device sharing, data
and information can also be shared among groups op computer, thus creating a
large information and knowledge base.
1.5 GENERATIONS OF COMPUTER

Over the years, various computing devices were invented that enabled
people to solve different types of problems. All these computing devices can be
classified into several generations. Generations refers to the phases of
improvement made to different computing devices resulted in a small, cheap,
fast and reliable computer. There are five generations of computer.
 First Generation Computers
 Second Generation Computers
 Third Generation Computers
 Fourth Generation Computers
 Fifth Generation Computers

1.5.1 First Generation Computers [1940 – 1956]

First generation computers are based on Vacuum Tube technology. A


vacuum tube is made up of glass and contains filaments inside it. The filaments
when heated generate electrons which eventually help in amplification and de
amplification of electronic signals. These computers used vacuum tubes for
circuitry and Magnetic drums for memory. Vacuum Tube technology is used for
calculation as well as for storage and control purposes.

Vacuum Tubes

Input was based on Punched Cards and paper tape. Output was in the form of
Printouts. Machine Language (i.e., 0 & 1) is used to perform operations of
computer. First Generation computers can solve only one problem at a time.
Some examples of first generation computers are
ENIAC  Electronic Numerical Integrator and Calculator
EDVAC  Electronic Discrete Variable Automatic Computer
EDSAC  Electronic Delay Storage Automatic Calculator
UNIVAC  Universal Automatic Computer

Advantage

 These computers were the fastest computing devices of their time.


 Execute complex mathematical problems in an efficient manner.
 Computations was performed in milliseconds
Disadvantage
 It requires larger space and non portable.
 It produces more heat.
 It requires more power consumption
 It was too expensive
 No reliability
 Programming was very difficult due to machine language

1.5.2 Second Generation Computers [1956 – 1963]

Second generation computers are based on Transistor, which was superior


to vacuum tubes. Transistors made up of semiconductor material like silicon and
germanium, it increases the power of incoming signals. It has 3 leads (Emitter,
Base and Collector) and performs electrical function such as voltage, current of
power etc. Base terminal acts as the input gate for the transistor. The collector of
the transistor is used to collect the amplified signal. The emitter of the transistor
acts as the output gate for emitting the amplified signal to the external
environment.

Transistors

Since transistor is a small device, size of the computer is reduced. Input of


second generation computer was Punched card and output was Printouts.
Magnetic cores are used as primary memory and Magnetic disks are used as
secondary memory. Some examples of second generation computers are PDP,
IBM 1401, IBM 7090 etc

Advantage

 Since second generation was based on Transistor technology, computers


during this generation were small in size.
 Generate less heat.
 Works at high speed and provide better reliability
 Computations was performed in microseconds

Disadvantage
 Cost of these computers was very high.
 It need air-conditioning
 Commercial products were difficult.

1.5.3 Third Generation Computers [1964 – Early 1970]

Third generation computers are based on Integrated Circuit(IC)


Technology. IC technology was also known as Microelectronics technology. IC
consists of a single chip, usually silicon in which transistors and resistors are
fabricated on it. Use of these integrated circuits made third generation
computers smaller in size, reliable and efficient than first and second generation
computers. ICs were superior to vacuum tubes and transistors in terms of cost
and performance.

Integrated Circuit(IC)

Input of third generation computer was Keyboard. Output was Monitor.


These computers allow user to run many application at same time. Some
examples of third generation computers are NCR 395, B6500, IBM 370, PDP 11,
CDC 7600 etc.

Advantage

 Computational time was reduced from Microsecond to Nanoseconds.


 It is easily portable and more reliable.
 Less power consumption and low cost for maintenance.
 It supports High Level Language.

Disadvantage

 It requires Air-conditioning for maintenance.


 Highly sophisticated technology required for manufacture of IC chips.
 Storage capacity of these computers was still very small.

1.5.4 Fourth Generation Computers [Early 1970’s – Till Date]


Fourth generation computers are based on Integrated and Microprocessor.
Microprocessor is built as a single piece of silicon called Chip with 0.5cm long
and not more than 0.05cm thick.

Microprocessors

Fourth generation computers used various Integrated Circuits as follows

LSI  Large Scale Integration allowed thousand transistors to be fitted


in one chip.
VLSI  Very Large Scale Integration allowed hundreds of thousand
transistors to
be fitted in one chip.
ULSI  Ultra Large Scale Integration allowed millions of transistor onto a
single chip.

Personal Computers (PCs) were developed during the fourth generation


computers. Input used in these generation computers is Keyboard, Mouse, GUI
(Graphical User Interface). GUI is user-friendly interface that allows user to
interact with the computer through icons and menus. Output is Monitor.
Operating System is used in this generation computers. Operating system is
software which provides interaction between user and hardware without OS
fourth generator computers cannot be utilized. Some examples of fourth
generation computers are Intel, IBM, Apple Series I and II etc.

Advantage

 Computers are very small.


 It is portable and quite reliable.
 Production cost is very low and low maintenance cost.
 Supported with programming language and GUI

Disadvantage

 Highly sophisticated technology required for manufacture of IC chips.


 Working of these computers is still dependent on the instructions given by
the programmer.
1.5.5 Fifth Generation Computers [Present and Beyond]
Fifth generation computers are based on Very Large Scale Integrated
Chips (VLSI) and Super Large Scale Integrated Chips (SLSI). The goal of fifth
generation computers is to develop computers that are capable of learning and
self-organization. Characteristics of fifth generation computers are,

 Mega Chip: Fifth generation computers require a great amount of storage


space since SLSI holds millions of electronic component on single chip.

 Parallel Processing: Fifth generation computers support parallel


processing i.e., processing several instructions at once.

 Artificial Intelligence: Artificial Intelligence tries to simulate and


reproduce human behaviour like thinking, speaking, reasoning etc.
Artificial Intelligence comprises of Expert System (ES) which make
decisions in real-life situations (For example, some expert systems helps
the doctors to diagnose disease based on the symptoms). Natural
language processing, speech recognition, voice recognition and robotics
are also included in the fifth generation computers.

Advantage

 Portable PC was invented in this generation.


 It is User-friendly.
 It supports parallel processing, which completes many tasks at a time.
 Fast and Large storage capacity is made available.

Disadvantage

 It does not provide intelligent program that could guide them in


performing different operations.
1.5.6 Comparison of various computer generations

Oper Opera
Technol
Gener Yea Input & Langua ating ting Applicatio Exampl
ogy
ation r Output ge Used Syst Spee n e
Used
em d
Punched
194 Machine ENIAC
Card, Simple
0- Vacuum Languag Millise EDVAC
First Paper None business
195 Tube e i.e., 0 conds EDSAC
Tape & application
6 &1 UNIVAC
Printout
PDP-8
195 Assembl Business
Punched Micros IBM
6- y and
Second Transistor Card & None econd 1401
196 Languag scientific
Printout s IBM
3 e research
7090
High
level
196 Integrate Languag Business
Nanos
4- d Keyboard e, Basic, and NCR 395
Third Yes econd
197 Circuit(IC & Monitor COBOL, scientific B6500
s
0 ) Pascal, research
C, C++
etc
High
Engineering
level
197 Microproc Keyboard, 1 to Design,
Languag Apple
0- essor & Mouse,GU 10 Scientific
Fourth e, C, C+ Yes Series I
Till LSI, VLSI I& Nanos research,
+, JAVA, & II
Date & ULSI Monitor econd online
Oracle,
systems.
SQL etc
High 1 to
198 Speech
level 100
6-at VLSI & recognition, Robotics
Fifth Languag Yes Nanos
pres SLSI Robotics , AI etc
e, 3GL, econd
ent etc
4GL etc s
1.6 CLASSIFICATION OF COMPUTERS

Now-a-days computers are available in different types. The function of each type
of computer is to process data and provide some output to users. Computers are
classified based on three criteria’s.

 Based on operating principles


i. Analog computer
ii. Digital computer
iii. Hybrid computer
 Based on Applications
i. General Purpose computer
ii. Special Purpose computer
 Based on Size and capacity
i. Micro computer
ii. Mini computer
iii. Mainframe computer
iv. Super computer

1.6.1 Based on operating principles

On the basis of operation performed and method used to store and


process data and information, computers are classified into following categories.

i. Analog Computer

Analog computer represents data as physical quantity and operates data


by manipulating the quantities. Analog computers were especially useful in the
simulation of dynamic situations. However, the results produced by these
computers are not accurate. Therefore, it is widely used in applications in which
the accuracy is not a major concern. They are powerful tools to solve differential
equations.

Example: Computing Blood pressure, Patient heart beat etc.

Disadvantage

 Output is not accurate.


 Low speed
 It has limited applications.
 Less memory space.
 Not suitable for business and industries.

ii. Digital Computer

Digital computers stores and process the data in a digital form. Each type
of data is stored in terms of 0s and 1s. Output produced by these computers is
also in the digital form. The digital computer is also known as digital information
processing system. Digital computers are generally faster and more reliable than
the analog computer systems and provide more accurate results. The computer
used by a home user is a typical example of a digital computer. It is used in
colleges, universities and business. Different hardware components of a digital
computer are ALU(Arithmetic and Logical Unit), CU(Control Unit), memory unit
and I/O units.

Example: Microcomputers, Palmtop computer, Super computer etc.

Advantage

 Large memory space.


 Highly suitable for business application.
 Output is represented in the form of discrete and output is accurate.
 It is versatile in nature.

iii. Hybrid Computer

Hybrid computer is combination of Analog and Digital computer. A hybrid


computer contains some special devices by the use of which the analog value
could be connected into the digital and vice versa so that the desired output can
be accomplished. In these computers, data is generally measured and processed
in the form of electrical signals and is stored with the help of digital components.
Hybrid computers are also less expensive than the digital computer. The
computer used in hospitals to measure the heartbeat of a patient is very good
example of a hybrid computer.

Advantage

 Hybrid computers are reliable and provide accurate result.


 These computers are fast and speedy.

Difference between analog and digital computer

Analog Computer Digital Computer


It represents physical quantity It represents discrete values
Data is in the form of signal Data is in the form of 0s and 1s
Less Accurate More Accurate
Less speed and low memory High speed and high memory
Example: Blood pressure Example: Personal computer
measurement

1.6.2 Based on applications

Computers are designed for designed for different purpose so that they
can perform their tasks according to their capabilities. On the basis of different
applications or purposes, computers can be classified into the following
categories.

i. General purpose computers

Computer designed to perform various operations based on the needs of


the society. It is used to perform financial accounting, mathematical calculation,
business and also in entertainment. The general-purpose computers are versatile
and can store a number of programs meant for performing distinct task.
Example: User PC, Laptop used for various purposes.
ii. Special purpose computers

Computer designed to perform only specific task. In this computer, the


programs are permanently designed and are not versatile in nature. These
computers are less expensive, efficient and consume less amount of time in
generating the result.

Example: Computer used for satellite launching, Aircraft controlling system etc.

1.6.3 Based on size and capacity

Computers differ from each other in terms of their shape, size and
weights. Based on the size and their capacity, computers can be classified into
four categories.

i. Micro Computer

Micro computer are stand-alone, low cost, single user digital


computer. They consist of CPU, Input unit, Storage unit, Memory unit etc. They
can be connected together to create network. Microcomputers are small, low-
cost and single –user digital computer. It consists of CPU, input unit, output unit,
storage unit and the software. A microcomputer is a computer whose CPU is
based on a microprocessor.

Additionally, the micro computer is named after the micro-processor which


is a single micro chip that largely forms the brain of the computer and which the
computer uses in its data processing. Microcomputers are stand-alone machines,
they can be connected together to create a network of computers that can serve
more than one user.

Examples:

IBM-PC Pentium 100, IBM-PC Pentium 200 and Apple Macintosh

Advantage

 It is the smallest of computer family.


 It is several times cheaper than the minicomputers.
 Highly reliable and require less maintenance.

Disadvantage

 Limited memory availability.


 Hard to maintain and replace.

Microcomputers include desktop computers, note-book computers or laptop,


tablet computer, handheld computer, smart phones and net book.

Desktop computer or personal computer (PC)

A desktop computer or personal computer (PC) is the most common type


of micro computer. It is principally intended for stand-alone use by an individual.
These micro computers typically consist of a system unit, a display
monitor, a keyboard, internal hard disk storage and other peripheral devices.
They are not very expensive for the individuals or for the small businesses.

Examples:

APPLE, IBM, Dell and Hewlett-Packard

Note –book computers or laptop

A laptop is a portable computer that a user can carry around. Since the
laptop resembles a notebook, it is also known as notebooks ..
The biggest advantage of laptops is that they are lightweight and can be
used anywhere and at any time, especially while travelling.
Moreover, they do not need any external power supply as a rechargeable battery
is completely self-contained. However, they are expensive as compared to
desktop computers.

Net Book

These computers are as powerful as desktop but size of these computers are
comparatively smaller than laptop and desktop. They weigh 2 to 3 kg. They are
more costly than laptop.

Net Book  Internet + Notebook

Tablet computer

It is portable computer. Tablet computer are the new kind of PCs. It will
be use a stylus or a pen, or a keyboard and mouse.

Handheld computer or personal digital assistant (PDA)

A hand-held computer such as PDA is a portable computer that can be


stored in a pocket (of sufficient size) and the user is holding it. PDAs are slightly
bigger than the common calculators. A PDA user generally uses a pen or
electronic stylus, instead of a keyboard for input.

The monitor is very small and is the only apparent form of output. Since
these computers can be easily fitted on the top of the palm, they are also
known as palmtop computers.

Hand-held computers usually have no disk drive, They have limited


memory and less powerful .PDAs can be connected to the internet through a
wireless connection.

Apple Newton, Casio Cassiopeia, and Franklin eBook Man are some of
the examples of hand-held computers.

Smart phones

Smart phones are cellular phones that can be act as a phone and as a
small PC. It will be use a stylus or a pen, or a small keyboard. They can be
connected to the internet wirelessly. They are used to access the e-mail,
download music, play games, etc.
Blackberry, Apple, HTC, Nokia and LG are some of the manufactures of smart
phones.

ii. Mini Computer

Mini computers are also powerful computers. Mini computers are


digital computers, used in multiuser system which supports 4-2000 users
simultaneously. They have high processing and high storage capacity than
microcomputer. A mini computer is a small digital computer (mid-range
computer). They have high processing speeds and high storage capacity than
the microcomputers. It is capable of supporting 4 to 200 simultaneous users.
Mini computers are usually multi-user systems; therefore they are used in
interactive applications in industries, research organizations, colleges and
universities. They are also used for real-time controls and engineering design
work. High-performance workstations with graphics I/O capability use mini
computers. Some of the widely used mini computers are PDP 11, IBM (8000
series) and VAX 7500.

Advantage

 They are used for real time applications like industries, research centres
etc.
 Occupies less space the mainframe
 Economically effective than mainframe

Disadvantage

 Computation speed is much lesser than mainframe computers.


 Memory of minicomputer is smaller than mainframe.

iii. Mainframe Computer

Mainframe computer are large powerful system and operate at a very high
speed. They are multi-user, multi-programming and high performance computer.
Mainframe computers are used in organization like bank or companies, where
many people require frequent access to the same data.

A mainframe (also known as “big iron”) is a high-performance computer


used for large-scale computing purposes that require greater availability and
security than a smaller-scale machine can offer. Historically, mainframes have
been associated with centralized rather than distributed computing, although
that distinction is blurring as smaller computers become more powerful and
mainframes become more multi-purpose. Some examples of mainframes are
CDC 6600 and IBM ES000 series.

Advantage

 A single mainframe can replace dozens or thousands of small sever.


 They can handle very high volume of input, output and high throughput.

Disadvantage

 Too expensive.
 Occupies more space.
iv. Super Computer

Supercomputers are the largest, fastest and the most expensive


computers. They have a large memory capacity and very high processing speed.
The speed of a supercomputer is generally measured in FLOPS (Floating point
Operations Per Second). It can solve the very difficult and complex problems
within a nano seconds. It is multi-user, multiprocessor large computer with a
very high efficiency and storing capacity.
It is used to weather fore-casting, climate research (global warming),
molecular research, biological research, nuclear research, aircraft design,
military research and defence systems. They are used major in military
agencies. Some examples of supercomputers are IBM roadrunner, IBM blue
gene and Intel ASCI red, CRAY-3, Cyber 205 and PARAM

Advantage

 Processing speed is in trillions per second.


 Several processor works simultaneously.
 It has more main memory.

Disadvantage

 Largest in size and most expensive in price than any other variety.
1.7 BASIC ORGANIZATION OF COMPUTER

The basic organization of computer explains the way in which different


units of the computer are interconnected with each other. Basic units of a
computer organization are,

 Input Unit
 CPU
 Memory Unit
 Output Unit

Block diagram of the computer system is given as below

Input Unit Memory Output Unit


Unit

Cache
Memory

Register

ALU

Control Unit
CPU

1.7.1 Input Unit

An input unit is an electronic device used to feed input data to


computer. It accepts data from the user. Computers need to receive data and
instruction in order to solve any problem. Therefore we need to input the data
and instructions into the computers. The input unit consists of one or more input
devices.

Major Functions of input unit are,


 Accept the data and instructions from the outside world.
 Convert it to a form that the computer can understand.
 Supply the converted data to the computer system for further processing.

Some examples of input devices are,


 Keyboard
 Mouse
 Scanner
o OMR
o OCR
o MICR
 Card Reader
 Webcam etc

Keyboard

Keyboard is the standard input device attached to all the computers. The
layout of the keyboard is just like the traditional typewriter of the type QWERTY.
It also contains some extra command keys and function keys. It contains a total
of 101 to 104 keys. A typical keyboard used in a computer is shown in figure.

You have to press correct combination of keys to input data. The computer
can recognize the electrical signals corresponding to the correct key combination
and processing is done accordingly.

Mouse

Mouse is an input device used with your personal computer. It rolls on a


small ball and has two or three buttons on the top. When you roll the mouse
across a flat surface the screen sensors the mouse in the direction of mouse
movement. The cursor moves very fast with mouse giving you more freedom to
work in any direction. It is easier and faster to move through a mouse.

Scanner

The keyboard can input only text through keys provided in it. If we want to
input a picture the keyboard cannot be used. Scanner is an optical device that
can input any graphical matter and display it back. The common optical scanner
devices are OMR, OCR and MICR.

i. OMR

Optical Mark Reader is used when students have appeared in objective


type tests and they had to mark their answer by darkening a square or circular
space by pencil. These answer sheets are directly fed to a computer for grading
where OMR is used.

ii. OCR

Optical Character Recognition is technique unites the direct reading of any


printed character. Suppose if there is a set of hand written characters in the
paper; the paper is a set of hand written characters in the paper, paper is put
inside the scanner of the computer.

iii. MICR

Magnetic Ink Character Recognition is widely used by banks to process


large volumes of cheque and drafts. Cheques are put inside the MICR. As they
enter the reading unit the cheques pass the magnetic field which causes the
read head to recognise the character of the cheques.

Card Reader

Card reader was punched cards for giving information into the computer.
The computer program which is to be fetched, transformed into punched cards
by the process known as card punching. After punching all the cards, they are
given to the card reader and computer reads the cards one by one. The card
reader converts information represented by the punched holes into electric
pulses.

Webcam

A Webcam is a video camera that feeds its image in real time to a


computer or computer network. A webcam is generally connected by a USB
cable.

1.7.2 CPU
The task of performing operations like arithmetic and logical operations is
called processing. Central Processing Unit (CPU) takes data and instructions from
the storage unit and makes all sorts of calculations based on user instruction.
CPU is often called as “Brain of Computer”. CPU controls, coordinates and
supervises the operations of the computer.

Main functions of CPU include 4-phases

 Fetching instruction from the memory.


 Decoding the instruction to decide what operations are to be performed.
 Executing the instruction.
 Storing the results back in the memory.

CPU consists of three main components

i. ALU
ii. Control Unit
iii. Register

i.ALU

All calculations are performed in the Arithmetic Logic Unit (ALU) of the
computer. ALU involves two main operations,

Arithmetic Operation

The major operations performed by the ALU are addition, subtraction,


multiplication and division.

Addition  6+5 = 11
Subtraction  6 – 5 = 1
Multiplication  6 * 5 = 30
Division  6/3 = 2

Logical Operation

The circuits of logic unit enables the CPU to perform logical operations like
AND, OR, XOR, NOT etc., Logical operation involves comparison of two numbers.
Comparison operations are,

<  Less than (Example: 2<5)


<=  Less than or equal to (Example: 5<=5)
>  Greater than (Example: 5>2)
>=  Greater than or equal to (Example: 5>=5)
==  Equal to (Example: 5=5)

ii. Control Unit


Control Unit (CU) organizes the data processing and instructions
execution. Control Unit act as a supervisor. It co-ordinates input and output
devices of the computer. It instructs ALU to perform its operation. Control Unit
tells when to fetch data, what to do, where to store the result etc.

iii. Register

Registers are high speed storage areas. Registers store data, instructions,
addresses and intermediate results of processing. It is called as “CPU’s working
memory”. Registers are not referenced by their address, but are directly
accessed and manipulated by the CPU during instruction execution.

Example: If 2-numbers are to be added, that 2-numbers are brought in the


register, added and again stored in register.

ADD R1, R2  Values of register R1 and R2 are added and result stored in
Register R1

Some of the important registers are,

i. ACC  Accumulator register, stores the results of arithmetic and logical


operation. It is
default register. Example: ADD B  Value of Accumulator register & B
register
is added, result stored back in Accumulator register.
ii. PC  Program Counter, stores the address of next instruction. Example:

1000 ADD B
1003 SUB C

In above code, while computer executing first instruction (ADD B), PC


register
contain (PC=1003) address of next instruction.
iii. IP  Instruction Register contain current instruction most recently fetched.

iv. DR  Data Register stores the operands and any data needed.

v. MAR  Memory Address Register contains address of next location in memory


to be

accessed.

vi. MBR  Memory Buffer Register temporarily stores data to be sent to memory.

1.7.3 Memory Unit

Memory refers to the electronic holding place for the instruction


and data. CPU requires memory to handle intermediate results and to store
final output. A memory is just like a human brain. It is used to store data and
instructions. Computer memory is the storage space in computer where data is
to be processed and instructions required for processing are stored. The
memory is divided into large number of small parts. Each part is called cell.
Each location or cell has a unique address, which varies from zero to memory
size minus one. There are three main types of memory,

i. Primary Memory
ii. Cache Memory
iii. Secondary Memory

i. Primary Memory

Primary memory is also called as Main Memory. It is an integral


component of CPU, placed on the computer motherboard. It is used to store
data and instructions during processing. Primary memory is of two kinds
a. RAM
b. ROM

a. RAM

Random Access Memory used to store all data and information in it when
the computer is ON. Content of the RAM are lost when the power is turned OFF,
hence it is called as Volatile Memory. RAM is a temporary memory. It provides
limited storage capacity, due its high cost.

b. ROM

Read Only Memory used to store all data and information permanently.
Content of the ROM are not lost when the power is turned OFF, hence it is called
as Non-Volatile Memory.

ii. Cache Memory

Cache memory is used to store data and information that was last
processed in CPU. When processor perform processing, first it searches cache
memory and then in RAM. It increases the speed of computer. Cache memory
is a very high speed semiconductor memory, which can speed up CPU. It acts
as a buffer between the CPU and main memory.
It is used to hold those parts of data and program which are most
frequently used by CPU. The parts of data and programs are transferred from
disk to cache memory by operating system, from where CPU can access them.

iii. Secondary Memory

This type of memory is also known as external memory or non-volatile. It


is slower than main memory. These are used for storing Data/Information
permanently.

CPU directly does not access these memories; instead they are accessed
via input-output routines. Contents of secondary memories are first transferred
to main memory and then CPU can access it.
Some examples of secondary memory are,
 Magnetic tape
 Hard Disk
 Floppy disk
 Compact Disc (CD)
 Digital Video Disk (DVD)
 Universal Serial Bus (USB) or Pen drive etc.,

1.7.4 Output Unit

The output unit of a computer provides the information and results


of a computation to outside world. Output unit consists of devices with the
help of which we get the information from computer. This unit is a link
between computer and users. Output devices translate the computer’s
output into the form understandable by users.

Following are few of the important output devices, which are used in
Computer Systems:
• Monitors
• Graphic Plotter
• Printer
Important Questions

2 Mark

1. Define computer.
2. List out characteristic of computer.
3. List applications of computer.
4. Define software. Give its types.
5. Differentiate system software and application software.
6. State the difference between analog and digital computer.
7. What is diligence and versatility?
8. What are the basic operations of computer?
9. Define parallel processing.
10.Differentiate general and special purpose computer.
11.What are the three criteria used for classification of computer?
12.What are mainframe computer?
13.For what super computer used for?
14.What is hybrid computer?
15.State the main functions/operations of CPU.
16.What is ALU?
17.Define register. List out its types.
18.Differentiate RAM & ROM.
19.What is cache memory?
20.What is secondary memory? Give example.

16 Mark or 8 Mark

1. Characteristics of computer.
2. Explain in detail about various generation of computer with example.
3. Brief about classification of computer.
4. Explain the classification of computer based on size and capacity.
5. With neat diagram explain in detail about Basic organization of
computer.
CHAPTER 2

NUMBER SYSTEM

2.1 INTRODUCTION

Number system is used to represent the numbers. There are infinite


ways to represent a number. All the number systems used by computer
professionals to interact with computers systems come under the category of
positional number system. The positional number system is a number system
in which numbers are represented using some symbols called digits and the
values of these numbers can be determined by taking the position of digit
consideration. Most commonly used number systems are,

i. Binary Number system


ii. Octal Number system
iii. Decimal Number system
iv. Hexadecimal Number system

2.1.1 Binary Number System

Binary number system is the most basic number system. Binary


number system uses Base 2 to represent the different values. Therefore, the
binary system is also known as base-2 system. Binary number system is based
on 2-digits (0 & 1). These binary digits are called as BITS. It can be represented
as

1 0 0 1 0 . 1 0 1 1

MSB Binary Point LSB

MSB  Most Significant Bit


LSB  Least Significant Bit

Example

(10101.011)2
(1001.10)2

2.1.2 Octal Number System

Octal number system uses Base 8 to represent different values. Therefore,


the octal system is also known as Base-8 number system. The digits used in octal
number system are 0, 1, 2, 3, 4, 5, 6 and 7. Octal number can be determined by
power of 8.

Example

(175.36)8
(12564.57)8
2.1.3 Decimal Number System

Decimal number system is most commonly used among people. It uses


Base 10 to represent different values. Therefore, the decimal system is also
known as Base-10 number system. Decimal number system consists of 10 digits
(0 – 9). Decimal number system can be used to represent both integers and
floating point values.

Example

(175.896)10
(9564.58)10

2.1.4 Hexadecimal Number System

Hexadecimal number system is used as an intermediary system in


computer. It is mainly used in representation of memory address or
representation of colour (Value to represent Red Colour: #FF0000). It uses Base
16 to represent different values. Therefore, the hexadecimal system is also
known as Base-16 number system. Decimal number system consists of 16 digits
(0 – 9, A, B, C, D, E, F).

Decimal 1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9
Number 0 1 2 3 4 5
Hexadecim
0 1 2 3 4 5 6 7 8 9 A B C D E F
al Number

Example

(175.896)16
(95A4B.5EF) 16
(4A9.2B) 16

2.1.5 Other types of number systems

BCD System

Binary Coded Decimal (BCD) is used to encode decimal number into binary
number. This is generally accomplished by encoding each digit of the decimal
number into its equivalent binary sequence. Advantage of BCD is fast and
efficient than conversion of pure decimal to binary. BCD system contains various
codes.

i. Weighted 4-bit BCD Code


ii. Excess 3 BCD Code
iii. Weighted 8-bit BCD Code
a. EBCDIC
b. ASCII
c. Gray Code

i. Weighted 4-bit BCD Code


Weighted 4-bit BCD Code uses only 4-bit binary number sequence. It is
commonly known as 8421 weighted code.

Hexadeci
Decimal
mal BCD Code
Number
Number
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111

ii. Excess 3 BCD Code

In Excess 3 code, decimal number is converted into 4-bit BCD equivalent by adding 3 to all
the digits of number. It is also known as non-weighted BCD code. It is also represented as “XS3 BCD
Code”.

Adding 3
Decimal
to each BCD Code
Number
digit
0 3 0011
1 4 0100
2 5 0101
3 6 0110
4 7 0111
5 8 1000
6 9 1001
7 10 1010
8 11 1011
9 12 1100

Example:
1. Convert given decimal number 173 into Excess 3 BCD Code.

Given decimal number is 173.

 Now add 3 to each digit of the given decimal number.

 Then convert those digits to its BCD equivalent.

11+3=4  0100
7  7 + 3 = 10  1010
33+3=6  0110

Answer: 173 
010010100110

2. Convert given decimal number 856 into XS 3 BCD Code.

Given decimal number is 856.

 Now add 3 to each digit of the given decimal number.

 Then convert those digits to its BCD equivalent.

8  8 + 3 = 11  1011
55+3=8  1000
66+3=9  1001

Answer: 856 
101110001001

iii. Weighted 8-bit BCD Code

8-Bit BCD systems were developed to overcome the limitations of 6-bit


BCD systems. The 6-bit BCD systems can handle numeric as well as non-numeric
data but with few special characters. The 8-bit BCD systems can handle

 Numeric data
 Non-Numeric data
 Almost all the special characters such as +, -, *, /, @, $ etc.

There are three most popular 8-bit BCD codes. They are

a. EBCDIC Code

Extended Binary Coded Decimal Interchange Code (EBCDIC) is an 8-bit


alphanumeric code that was developed by IBM to represents alphabets, decimal
digits and special characters. The EBCDIC codes are generally the decimal and
the hexadecimal representation of different characters. This code is rarely used
by non IBM computer systems.

Hexadeci
Characte Decimal
mal
rs Number
Number
NUL 0 00
STX 2 02
ESC 39 27
SUB 63 3F
[ 74 4A
. 75 4B
< 76 4C
( 77 4D
+ 78 4E
& 80 50
$ 91 5B
* 92 5C
- 96 60
/ 97 61
% 108 6C
? 111 6F
= 126 7E

b. ASCII Code

American Standard Code for Information Interchange (ASCII) is used or the same purpose for
which the EBCDIC code. It is pronounced as ASKEE. This code is more popular, this code can be
implemented by most of the non-IBM computer systems.

Hexadeci
Characte Decimal
mal
rs Number
Number
NUL 0 0
STX 2 2
ESC 27 1B
# 35 23
$ 36 24
% 37 25
& 38 26
* 42 2A
+ 43 2B
/ 47 2F
< 60 3C
= 61 3D
> 62 3E
0-9 48-57 30-39
A-Z 65-90 41-5A
a-z 97-122 61-7A
C. Gray Code
Gray code is another important code that is also used to convert the
decimal number into an 8-bit binary sequence.

Gray code to binary code

1. MSB (Most Significant Bit) of Binary code is same as MSB of Gray code

2. Next MSB of Binary can be determined by adding MSB of Binary with next
MSB of gray coded number.

Example

1. Convert given gray code 11010011 to binary code

Gray Code 1 1 0 1 0 0 1 1

Binary Code 1 0
0 1 1 1 0 1

 MSB of Binary Code  1 (Same as MSB of Gray Code)


 Next MSB of Binary Code  1 + 1= 0 (MSB of Binary Code + Next MSB of Gray
code)
 Next MSB of Binary Code  0 + 0= 0
 Next MSB of Binary Code  0 + 1= 1
 Next MSB of Binary Code  1 + 0= 0 and so on until last bit of gray code.

Answer: Binary code = 10011101

2. Convert given gray code 11110010 to binary code

Gray Code 1 1 1 1 0 0 1 0

Binary Code 1 0
1 0 0 0 1 1

 MSB of Binary Code  1 (Same as MSB of Gray Code)


 Next MSB of Binary Code  1 + 1= 0 (MSB of Binary Code + Next MSB of Gray
code)
 Next MSB of Binary Code  0 + 1= 1
 Next MSB of Binary Code  1 + 1= 0
 Next MSB of Binary Code  0 + 0= 0 and so on until last bit of gray code.

Answer: Binary code = 10100011


Binary code to Gray code

1. MSB (Most Significant Bit) of Gray code is same as MSB of Binary code

2. Next MSB of Gray code can be determined by adding subsequent pair bits
of binary number starting from left.

Example

1. Convert given binary code 10011101 to gray code

+ + + + + + +
Binary Code 1 ----> 0 ----> 0 ----> 1 ----> 1 ----> 1
----> 0 ----> 1

Gray Code 1 1 0 1 0 0 1 1

Answer: Gray code = 11010011

2. Convert given binary code 10100011 to its equivalent gray code

+ + + + + + +
Binary Code 1 ----> 0 ----> 1 ----> 0 ----> 0 ----> 0
----> 1 ----> 1

Gray Code 1 1 1 1 0 0 1 0

Answer: Gray code = 11110010


2.2 Number Conversion

Computer systems accept data in decimal form, whereas data is stored


and processed in binary form. Therefore, it becomes necessary convert the
number represented in one system into the numbers represented in another
system. There are various types of number conversion as given below.

 Decimal to other number system


a. Decimal to binary
b. Decimal to octal
c. Decimal to hexadecimal
 Other number systems to decimal
a. Binary to decimal
b. Octal to decimal
c. Hexadecimal to decimal
 Other conversions
a. Binary to Octal
b. Binary to Hexadecimal
c. Octal to Binary
d. Hexadecimal to binary
e. Octal to Hexadecimal
f. Hexadecimal to Octal

2.2.1 Decimal to other number system

Decimal number is converted into other number system using LCM


method. There are there conversions under this category.

a. Decimal to Binary

1. Convert decimal number (147)10 to its Binary equivalent.

2 147
2 73 -1
2 36 -1
2 18 -0
2 9 -0
2 4 -1
2 2 -0
1 -0

Answer: (147)10 =
(10010011)2
2. Convert decimal number
(62.8125)10 to its Binary equivalent.
2 62
2 31 -0
2 15 -1
2 7 -1
2 3 -1
1 -1

(62)10 = (111110)2

Now,

0.8125 x 2 = 1 . 6250

0.6250 x 1 2 = . 2500

0.2500 x 0 2 = . 5000

0.5000 x 1 2= . 0000

(0.8125)10 = (0.1101)2

Answer (62.8125)10 =
(111110.1101)2

Solve the below problems to practise

1. (42)10 = (101010)2

2. (135.6875)10 = (10000111.1011)2

3. (59.6825)10 = (111011.1010111)2

4. (36)10 = (100100)2

5. (245)10 = (1110101)2

6. (0.4375)10 = (0.0111)2

7. (59.815)10 = (111011.1101)2

b. Decimal to Octal Number

1. Convert decimal number (1792)10 to its Octal equivalent.

8 1792
8 224 -0
8 28 -0
3 -4

Answer: (1792)10 = (3400)8

2. Convert decimal number (154.789)10 to its Octal equivalent.

8 154
8 19 -2
2 -3

(154)10 = (232)8
Now,

0.789 x 6 8= . 312

0.312 x 8 = 2 . 496

0.496 x 8 = 3 . 968

0.968 x 8 = 7 . 744

(0.789)10 = (0.6237)2

Answer (154.789)10 =
(232.6237)2
Solve the below problems to practise

1. (225.225)10 = (341.16314)8

2. (359)10 = (547)8

3. (756)10 = (1364)8

4. (399)10 = (617)8

5. (59.815)10 = (73.641)8

c. Decimal to Hexadecimal Number

1. Convert decimal number (754)10 to its Hexadecimal equivalent.

16 754
16 47 -2
2 - 15 (F)

Answer: (754)10 = (2F2)16


2. Convert decimal number (28.28125)10 to its Hexadecimal equivalent.

16 28
1 - 12 (C)

(28)10 = (1C)8
Now,

0.28125 x 4 16 = . 50000

0.50000 x 8 16 = . 00000

(0.28125)10 = (0.48)2

Answer (28.28125)10 =
(1C.48)2
Solve the below problems to practise

1. (428)10 = (1AC)16

2. (225.225)10 = (E1.399)16

3. (5112)10 = (13F8)16

4. (245)10 = (F5)16

5. (756)10 = (2F4)16

2.2.2 Other number system to Decimal Number

Other number system (Binary, Octal and Hexadecimal) is converted into


decimal number system using L-method. There are there conversions under
this category.

a. Binary to Decimal number

1. Convert given binary number (11110)2 to its Decimal equivalent.

4 3 2 1 0
1 1 1 1 0
0 x 20 =0x1 = 0
1 x 21 = 1 x 2 = 2
1 x 22 =1x4 = 4
1 x 23 = 1 x 8 = 8

1 x 24 = 1 x 16 = 16
-----------
30
------------

Answer (11110)2 = (30)10

2. Convert given binary number (10101.111)2 to its Decimal equivalent.

4 3 2 1 0 -1 -2 -3
1 0 1 0 1 . 1 1 1
1 x 2 = 1 x 0.125 = 0.125
-3

1 x 2-2 = 1 x 0.25 = 0.25


1 x 2-1 = 1 x 0.5 = 0.5
1x2 =1x1
0
= 1
0x2 =0x2
1
= 0
1x2 =1x4
2
= 4
0x2 =0x8
3
= 0
1 x 2 = 1 x 16
4
= 16
--------------
21.875
---------------

Home work Answer (10101.111)2 =


(21.875)10
1. Convert (11010)2 to its
decimal equivalent  (26)10

2. (1111111101.111111)2 = (1021.9562)10

3. (1011.010)2 = (11.25)10

4. (111011.1101)2 = (59.815)10

5. (10101101)2 = (173)10

b. Octal to Decimal number

1. Convert given Octal number (540)8 to its Decimal equivalent.

2 1 0
5 4 0
0 x 80 =0x1 = 0
4 x 81 = 4 x 8 = 32
5 x 82 = 5 x 16 = 320
-----------
352
------------

Answer (540)8 = (352)10

1. Convert given Octal number (24.36)8 to its Decimal equivalent.

1 0 -1 -2
2 4 . 3 6

6 x 8-2 =
6 x 0.015 = 0.090
3 x 8-1 = 3 x 0.125 = 0.375

4 x 80 = 4 x 1 = 4

2 x 81 = 2 x 8 = 16
-----------
20.465
------------

Home work Answer (24.36)2 = (20.465)10

1. Convert (245.14)8 to its decimal equivalent  (165.1875)10

2. (6245.14)8 = (3237.1874)10

3. (456)8 = (302)10

4. (127.54)8 = (87.6875)10

5. (325.12)8 = (213.1562)10

c. Hexadecimal to Decimal number

1. Convert given Hexadecimal number (28D)16 to its Decimal equivalent.


2 1 0
2 8 D

D x 160 = 13 x 1 = 13
8 x 161 = 8 x 16 = 128
2 x 162 = 2 x 256 = 512
-----------
653
------------

Answer (28D)16 = (653)10

2. Convert given Hexadecimal number (6BB.418)16 to its Decimal


equivalent.
2 1 0 -1 -2 -3
6 B B . 4 1 8

8 x 16-
3
= 8 x 0.00024
= 0.00195
1 x 16-2 = 1 x 0.0039 =
0.00390
4 x 16-1 = 4 x 0.0625 = 0.2500
B x 160 = 11 x 1 = 11

B x 161 = 11 x 16 = 176

6 x 162 = 6 x 256 = 1536


-----------------

1723.25585

-----------------
Home work Answer (6BB.418)16 =
(1723.25585)10
1. Find the decimal
equivalent of the hexadecimal 2B.C4  (43.7656)10

2. (A2B.D4)16 = (3237.1874)10

3. (D2763)16 = (862051)10

4. (64AC)16 = (25772)10

5. (B14)16 = (2836)10

2.2.3 Other Conversions

Other conversions are done using BCD-method. There are six conversions
under this category.
BCD Values to be used in other conversions are given below

Decimal Hexadeci
Octal Code
Number mal Code
0 000 0000
1 001 0001
2 010 0010
3 011 0011
4 100 0100
5 101 0101
6 110 0110
7 111 0111
8 - 1000
9 - 1001
10 (A) - 1010
11 (B) - 1011
12 (C) - 1100
13 (D) - 1101
14 (E) - 1110
15 (F) - 1111

a. Binary to Octal

Steps:
i. Group given binary digit into set of 3 digits starting from LSB (i.e.,
right).
ii. Pad the MSB with zeros if necessary to complete group of 3 digits.
iii. Replace each group by its octal equivalent.

1. Convert given binary number (11100101)2 to its octal equivalent.

0 1 1 / 1 0 0 / 1 0 1

3 4 5

Answer (11100101)2 = (345)8

2. Convert given binary number (111101100.0001)2 to its octal


equivalent.

1 1 1 / 1 0 1 / 1 0 0 . 0 0 0 / 1 0 0
7 5 4 0
4

Answer (111101100.0001)2 =
(754.04)8
Home work

1. (10111001100.1101011)2 = (2714.654)8

2. (1111111101.111111)2 = (1775.77)8

3. (1110.1011)2 = (16.54)8

b. Binary to Hexadecimal

Steps:
iv. Group given binary digit into set of 4 digits starting from LSB (i.e.,
right).
v. Pad the MSB with zeros if necessary to complete group of 4 digits.
vi. Replace each group by its hexadecimal equivalent.

1. Convert given binary number (11100101)2 to its hexadecimal


equivalent.

1 1 1 0 / 0 1 0 1

E 5

Answer (11100101)2 = (E5)16

2. Convert given binary number (110011101.110101)2 to its


hexadecimal equivalent.

0 0 0 1 / 1 0 0 1 / 1 1 0 1 . 1 1 0 1 / 0 1 0 0

1 9 D . D 4

Home work Answer (110011101.110101)2 =


(19D.D4)16
1. (11010011) 2

= (D3)16

2. (1111111101.111111)2 = (3FD.FC)16

3. (1101001101110111)2 = (D377)16

c. Octal to Binary
To convert given octal number to binary number, write the corresponding
group of 3 digits BCD code for each octal digit.

1. Convert given octal number (6347)8 to its binary equivalent.

6 3 4 7

110 011 100 111

Answer (6347)8 =
(110011100111)2
2. Convert given octal number (375.16)8 to its binary equivalent.

3 7 5 . 1 6

011 111 101 . 001 110

Answer (375.16)8 =
(011111101.001110)2

Home work

1. (654)8 = (110101100)2

2. (561)8 = (101110001)2

3. (231)8 = (010011001)2

d. Hexadecimal to Binary

To convert given hexadecimal number to binary number, write the


corresponding group of 4 digits BCD code for each hexa digit.

1. Convert given hexadecimal number (5C8)16 to its binary equivalent.

5 C 8

0101 1100 1000


Answer (5C8)16 =
(010111001000)2
2. Convert given hexadecimal number (43.10AB)16 to its binary
equivalent.

4 3 . 1 0 A B

0100 0011 . 0001 0000 1010 1011

Answer (43.10AB)16 =
(01000011.0001000010101011)2
Home work

1. Convert EBC16 to its binary equivalent  (111010111100)2

2. Convert the following hexadecimal to its binary equivalent 2C6B.F06 


(0010110001101011.111100000110)2

3. (FAC)16 = (111110101100)2

4. (2AC)16 = (001010101100)2

5. (5AF)16 = (010110101111)2

e. Octal to Hexadecimal

To convert given octal number to hexadecimal number, 2 steps to be


followed.

1. Octal to binary
2. Binary to Hexadecimal

Note: Procedure for above two had been solved in previous categories

1. Convert given octal number (2327)8 to its hexadecimal equivalent.

Step 1: Convert given octal to binary

2 3 2 7

010 011 010 111

(2327)8 = (010011010111)2
Step 2: Now convert obtained binary to hexadecimal

0 1 0 0/1 1 0 1/0 1 1 1

4 D 7

(010011010111)2 = (4D7)16

Final answer is
Answer (2327)8 = (4D7)16

2. Convert given octal number (463.52)8 to its hexadecimal equivalent.

Step 1: Convert given octal to binary

4 6 3 . 5 2
100 110
011 101 010

(463.52)8 =
(100110011.101010)2

Step 2: Now convert obtained binary to hexadecimal

0 0 0 1 / 0 0 1 1 / 0 0 1 1 . 1 0 1 0 / 1 0 0 0
1 3 3 . A 8

(100110011.101010)2 =
(133.A8)16
Final answer is
Answer (463.52)8 = (133.A8)16
Home work

1. (7521)8 = (?)16

2. (235.21)8 = (?)16
f. Hexadecimal to Octal

To convert given hexadecimal number to octal number, 2 steps to be


followed.

1. Hexadecimal to binary
2. Binary to Octal

Note: Procedure for above two had been solved in previous categories

1. Convert given hexadecimal number (A2DE)16 to its octal equivalent.

Step 1: Convert given hexadecimal to binary


A 2 D E

1010 0010 1101 1110

(A2DE)16 =
(1010001011011110)2

Step 2: Now convert obtained binary to octal

0 0 1 / 0 1 0 / 0 0 1 / 0 1 1 / 0 1 1 / 1 1 0
1 2 1 3 3
6

(1010001011011110)2 =
(121336)8
Final answer is
Answer (A2DE)16 = (121336)8

2. Convert given hexadecimal number (AC5.4D)16 to its octal equivalent.

Step 1: Convert given hexadecimal to binary

A C 5 . 4 D

1010 1100 0101 . 0100 1101

Step 2: Now (AC5.4D)16 = convert


obtained binary (101011000101.01001101)2 to octal
1 0 1 / 0 1 1 / 0 0 0 / 1 0 1 . 0 1 0 / 0 1 1 / 0 1 0
5 3 0 5 .
2
3 2

(101011000101.01001101)2 =
(5305.232)8
Final answer is
Answer (AC5.4D)16 = (5305.232)8

Home work

1. Find equivalent octal number for AF6  (5374)8

2. (2C6B.F06)16 = (26153.7406)8

3. (2B6)16 = (1266)8

4. Write binary and octal equivalent of hexadecimal number 7BD

(01110111101)2
(3675)8

2.3 Binary Arithmetic

Binary arithmetic is fundamental to all digital computer and most other


digital systems. The different arithmetic operations performed using the binary
numbers are

 One’s complement
 Two’s complement
 Binary addition
 Binary subtraction
 Binary multiplication
 Binary division

2.3.1 One’s complement


1’s complement of given binary number is found by changing all the 1s to
0s and vice versa.

Example

1’s complement of
Binary Number
binary number
10001 01110
101001 010110
111000 000111

2.3.2 Two’s complement

2’s complement of given binary number is found using 2 actions.


i. Find 1’s complement by changing all the 1s to 0s and vice
versa.
ii. Add 1 to the value of 1’s complement

Example

1. Find 2’s complement of binary number 10001.

i. 1’s complement of 10001  01110

ii. Add 1 to 01110  01110


1+
-----------
2’s complement  01111
------------

2. Find 2’s complement of binary number 101001.

i. 1’s complement of 101001  010110

ii. Add 1 to 010110  010110


1+
-----------
2’s complement  010111
------------

2. Find 2’s complement of binary number 101010.

i. 1’s complement of 101010  010101

ii. Add 1 to 010101  010101


1+
-----------
2’s complement  010110
------------

2.3.3 Binary Addition

Binary addition is the most important binary arithmetic process because it


can be used to perform all other arithmetic operations such as subtraction,
multiplication and division. Adding binary numbers is very similar to adding
decimal numbers.

Rules of binary addition

0+0=0
1+0=1
0+1=1
1 + 1 =0 and
carry = 1
1+1+1=1 and
carry = 1

Example

1. Add binary numbers 1011 and 1011

1 1  Carry
1 0 1 1
+ 1 0 1 1
--------------------------------
1 0 1 1 0
--------------------------------

Answer 1011 + 1011 =


10110

2. Add binary numbers 00011010 and 00001100

1 1  Carry
0 0 0 1 1 0 1 0
+ 0 0 0 0 1 1 0 0
-----------------------------------------------------------------------
0 0 1 0 0 1 1 0
------------------------------------------------------------------------

Answer 00011010 + 00001100 =


00100110
2.3.4 Binary Subtraction

Binary subtraction can be performed using two methods.

Method I  Using rules of binary subtraction


Method II  Using 2’s complement
a. Method I
Rules of binary subtraction

0-0=0
1-0=1
0-1=1 and
borrow=1
1 - 1 =0

Example

1. Subtract binary numbers 00100101 and 00010001

0 10  Borrow
0 0 1 0 0 1 0 1
-0 0 0 1 0 0 0 1
-----------------------------------------------------------------------
0 0 0 1 0 1 0 0
-----------------------------------------------------------------------

Answer 00100101 – 00010001 =


00010100

2. Subtract binary numbers 00110011 and 00010110

3rd 1st 2nd  Step order

0 10 0 10 1
10  Borrow
0 0 1 1 0 0 1 1
-0 0 0 1 0 1 1 0
-----------------------------------------------------------------------
0 0 0 1 1 1 0 1
------------------------------------------------------------------------

Answer 00110011 – 00010110 =


00011101

b. Method II

Subtraction using 2’s complement


This method involves three steps to be followed.

i. Find 2’s complement of 2nd number


ii. Add both numbers
iii. If carry occurs, discard it.

Example

1. Subtract binary numbers 00100101 and 00010001

Step 1: 2’s complement of 00010001

i. 1’s complement of 00010001  11101110

ii. Add 1 to 11101110  11101110


1+
--------------
2’s complement  11101111
--------------

Step 2: Add both numbers (00100101 + 11101111)

1 1 1 1 1 1  Carry
0 0 1 0 0 1 0 1
+ 1 1 1 0 1 1 1 1
-----------------------------------------------------------------------
1 0 0 0 1 0 1 0 0
Discard ------------------------------------------------------------------------

Step 3: Discard the carry

Answer 00100101 – 00010001 = Therefore,


00010100

Example

2. Subtract binary numbers 00110011 and 00010110

Step 1: 2’s complement of 00010110


i. 1’s complement of 00010110  11101001

ii. Add 1 to 11101001  11101001


1+
--------------
2’s complement  11101010
--------------

Step 2: Add both numbers (00110011 + 11101010)

1 1 1  Carry
0 0 1 1 0 0 1 1
+ 1 1 1 0 1 0 1 0
-----------------------------------------------------------------------
1 0 0 0 1 1 1 0 1
Discard ------------------------------------------------------------------------

Step 3: Discard the carry

Answer 00110011 – 00010110 = Therefore,


00011101

Home work

Solve below problems using Method I & Method II

1. 1011011 - 10010  1001001

2. 100010110 - 111010  010011100

3. 11001 – 10011  00110

4. 11101011 – 01100110  10000101

2.3.5 Binary Multiplication

Binary multiplication can be achieved using the long multiplication


method. That is, by multiplying each digit in turn, and then adding the values
together.

Rules of binary multiplication


0x0=0
1x0=0
0x1=0
1 x 1 =1 and no carry or
borrow bits

Example

1. Multiply binary numbers 1011 and 111

1 0 1 1 x 1 1 1

--------------------------------------------------------------------------
1 1 1 1

1 0 1 1
1 0 1 1
1 0 1 1
--------------------------------------------------------
1 0 0 1 1 0 1
--------------------------------------------------------

Answer 1011 x 111 = 1001101

2. Multiply binary numbers 00101001 and 00000110

1 0 1 0 0 1 x 1 1 0

------------------------------------------------------------------------------------------
0 0 0 0 0 0
1 0 1 0 0 1
1 0 1 0 0 1
-----------------------------------------------------------------------
1 1 1 1 0 1 1 0
-----------------------------------------------------------------------

Answer 00101001 x 00000110 =


11110110

2.3.6 Binary Division

Binary division is the repeated process of subtraction.

Example
1. Divide binary numbers 1011 ÷ 11

1 1  Quotient

11 1 0 1 1

1 1
------------------------
1 0 1

1 1
-----------------------
1 0  Remainder
-----------------------
Answer 1011 ÷ 11 = 11

2. Divide binary numbers 10000111 ÷ 101

1 1 0 1 1  Quotient

101 0 1 1 10

1 00 00 1 1 1

- 10 1
-----------------
0 0 1 10

- 1 0 1
--------- ----
0 01 11
1 01
--------- ---
0 10 1
10 1
-------------
0
------------
Answer 10000111 ÷ 101 =
11011

Home work

1. 101010 ÷ 110  111

2. 1001 ÷ 11  11
2.4 NEED FOR LOGICAL ANALYSIS AND THINKING

Logical thinking is essential for every programmer. The students, who are
into programming and learning it, should capable to think logically but basically
most of the beginners suffer a lot to think logical and improve logical thinking
skills.
Logic is a small code snippet or the part of the program which consist of set of
instruction to solve the given problem. Logic of the program is the actual
statements which are to be executed by the computer in order to solve the
problem. The logic for solving a problem is developed using set of instructions
and embedded them in a program by following the rules of writing a program

Computer cannot perform on its own. Computers need instructions to


perform a particular task. They perform variety of tasks like receiving data,
processing it and producing result. The computer work on set of instructions
called program to carry out a particular task.

Logic to solve the problem

Identify the
problem

Analyse the solution

Select the best


solution

To produce an effective result, programmer must take care of each and every
step in sequential order.

Steps to design a program

Steps involved in writing a program to solve a problem are given below. A


programmer must determine three basic steps.

1. Instruction  to be performed.
2. Sequence  in which those instructions are to be performed.
3. Data  required to perform those instructions.
To solve the problem using the computer, the following steps are
followed.

a. Problem must be analysed thoroughly.


b. Solution method is broken down into a sequence of small task.
c. Based on the analysis, an algorithm must be prepared to solve the
problem.
d. The algorithm is expressed in a precise notation. This notation is known as
program.
e. Program is fed into the computer.
f. Instructions in the program executed one after another.
g. Output is produced based on expected result.

Characteristics of a good program

The following are the characteristics of a good program.

1. Integrity  Accuracy of the result produced i.e., correctness of


calculations.

2. Clarity  Program should be clear and readable.

3. Simplicity  Program should be simple and easily understandable.

4. Efficiency  Efficiency includes execution speed and efficient memory


usage.

5. Modularity  Large program is broken into small modules which


increases the

accuracy and clarity of the program.

2.5 PROBLEM SOLVING TECHNIQUE

There are three ways to represent logical steps for finding the solution to a
given problem. They are

1. Algorithm

2. Flowchart

3. Pseudo code

2.5.1 ALGORITHM

An algorithm is a sequence of instruction for completing a task. Algorithm


is a sequence of finite, well-defined, unambiguous and ordered instruction.
Algorithm is an English-like representation of a logic which is used to solve the
problem.

Characteristics of an algorithm

1. It is simple to understand step by step solution of the problem.

2. An algorithm is independent of programming language.

3. Algorithm is precise and unambiguous.

4. Algorithm should be written in sequence.

5. It looks like normal English.

6. Result should be obtained only after the algorithm terminates.

Qualities of an algorithm

The factors that determine the quality of algorithm are

 Algorithm should provide accurate result than others.

 It should require minimum computer memory.

 The time taken to execute any program is considered as a main


quality. Lesser the time taken better the quality.

 Procedure of an algorithm must be in a sequential form.

Example

1. Algorithm for finding sum of 2 numbers

Step 1: Start
Step 2: Read 2-numbers A, B.

Step 3: Add 2-numbers and store result in C.

Step 4: Display the result “C”

Step 5: Stop.

2. Algorithm for finding sum and average of n -numbers

Step 1: Start

Step 2: Read limit of n-values i.e., number of values to be added.


Step 3: Read all n-values one by one

Step 4: Calculate sum of n-values and store result in “sum”

Step 5: Calculate average on n-values using formula sum/n.

Step 6: Print sum and average.

Step 7: Stop.

3. Algorithm for find greatest of 3-numbers

Step 1: Start

Step 2: Read 3 numbers A, B and C.

Step 3: Compare A and B. If A is greater perform Step 4 else perform Step


5

Step 4: Compare A and C. If A is greater, Print “A is great” else Print “C is


great”.

Step 5: Compare B and C, If B is greater, Print “B is great” else Print “C is


great”.

Step 6: Stop.

4. Algorithm for find greatest of 2-numbers

Step 1: Start

Step 2: Read 3 numbers A and B.

Step 3: Compare A and B.

Step 4: If A is greater, print “A is great” else Print “B is great”.

Step 5: Stop.

5. Algorithm to compute factorial of a number

Step 1: Start
Step 2: Read a number “n”

Step 3: Initialize the value of variable “fact” to 1.

Step 4: Set a loop to find the factorial of the given number “n” using
formula

fact=fact*i.

Step 5: Print the factorial of the given number

Step 6: Stop.

Practise algorithm for following questions

1. Algorithm to find difference and product of 2 given numbers.


2. Algorithm to find area of circle.
3. Write an algorithm to print Fibonacci series.
4. Write an algorithm to print numbers from 2 to 100.

5. Algorithm to compute Simple interest and compound interest.

6. Algorithm to find roots of quadratic equations.

7. Write an algorithm to add even numbers between 0 to 1000.

8. Algorithm to multiply two matrices.

2.5.2 FLOWCHART

A flowchart is a pictorial representation of an algorithm. A flowchart is


drawn using boxes of different shapes with lines connecting them to show the
flow of control. The purpose of drawing a flowchart is to make the logic of the
program clearly in a visual form. Since flowchart is a diagrammatic
representation, it forms a common medium of communication.

Flowchart Symbols

A flowchart is drawn using different kinds of symbols. A symbol used in a flowchart is for a
specific purpose. Their shapes and functions are predefined in nature.

SYMBOL Name of Symbol PURPOSE


Oval represent start and stop of
Terminal
the program
Parallelogram used to get input
Input / Output
and print the output
Rectangle used for representing
Process process, action, initialization
etc.

Diamond used to represent


Decision Making
decision or branch

Circle used to connect flowchart


Connector
that is long more than one page

Flow lines Indicate the direction of flow

Used to represent for loop


Preparation
statement

Used to represent functions


Predefined Process
used in C program

Need for flowchart

1. Flowchart makes the logic clear.


2. Useful in coding
3. Used for effective analysis.

Guidelines for preparing a flowchart

1. Flowchart should have start and end.


2. Flowchart must have direction of flow from top to bottom; left to right
properly indicated using flow lines.
3. Flowchart may be simple or complex.
4. Standard symbol should be used for the respective action.

Advantage / Benefits

1. A flowchart helps to clarify how things are currently working and how they
are improved.
2. It helps to remove repeated and misplaced steps.
3. It helps in monitoring important areas, data collections etc for increase in
efficiency.
Limitations / Disadvantage

1. Complex when program is very large


2. It is difficult to modify.
3. Costly and take more time

Design Structure of flow chart

There are 3 different design structure of flowchart. They are


a. Sequence control structure
b. Selection control structure
c. Iterative / loop control structure

a. Sequence control structure

In sequence control structure, the steps are executed in linear order one
after the other. Flow of the control is sequential in order from top to bottom.

Example

Flowchart for finding sum of 2-numbers

Start

Read A, B
Flow of given
flowchart is
C=A+B sequential

Print C

Start
b. Selection control structure

In selection control structure, the step to be executed next is based on


decision taken. If condition is true one path is followed. If condition is false
another path is followed. Hence flow of control will not be in linear order.

Example
Flowchart for finding greatest of 2-numbers

Start

Read A, B

No Print “B is
If
A> great”
B
Yes

Print “A is
great”

Stop

In the above flowchart, flow of control is not in sequential order. Here if


condition is true, path towards “Yes” branch will be flowed. If condition is false,
path towards “No” branch will be flowed. Hence flow of control is selected based
on a specific condition, it is called as “Selection control flowchart”.

c. Iterative control structure

In iterative control structure, a set of particular instruction is executed


repeatedly until specified condition is true. If specified condition is false, another
path is followed.

Example

Flowchart to find sum and average of n-numbers


Start

Read n

Fals
for e
(i=1;i<n;i+
+) Given true
statement is True
Read n Executed
repeatedly values
Until for loop fails

Sum of all
values

Start
Average =
sum/n

Read
A,B,C
Print sum
and
average
Yes No
If If
A>
Stop A>
B C

No Yes

No
If
B>
Flowchart to Print A Print C
C
find greatest
of 3-numbers Yes

Print B
Print C

Stop
Practise flowchart for following questions

1. Find odd or even number


2. Roots of quadratic equation
3. Multiplication of two matrix
4. Sum of even numbers
5. Factorial of given number
6. To print Fibonacci series

2.5.3 PSEUDO CODE

Pseudo code is an outline of a program written in the form that can be


easily converted into programming statements. Pseudo code use styled English
language to represent the process of computer program. Pseudo code is skeleton
form of all programming language.

Keywords of Pseudo code


There are few standard keywords used for representing various actions.
They are,

1. Input  READ, GET, INPUT


2. Output  PRINT, DISPLAY, SHOW, OUTPUT
3. Calculations  CALCULATE, COMPUTE, ADD, SUBTRACT, INITIALIZE
4. Incrementing  INCREMENT, DECREMENT

Guidelines of Pseudo code

1. Statement should be written in simple English.


2. Pseudo code should be programming language independent.
3. Pseudo code must be understandable and concise.
4. Each statement should express just one action for the computer.
5. Keyword in Pseudo code should be capitalized.

Benefits of Pseudo code

1. It is easy to develop a program from Pseudo code.


2. Pseudo code is compact, readable and easy to modify.
3. Since it is language independent, can be used by all programmers.

Limitations of Pseudo code

1. Pseudo code cannot be complied or executed.


2. These are no syntax rules, programmer use their own style.
3. It does not provide visual representation.

Example

1. Pseudo code to find sum of 2 numbers

READ A, B
COMPUTE C by adding A with B
PRINT C
STOP

2. Pseudo code to find sum and average of n-numbers

READ n
FOR (i=0;i<n;i++)
READ all inputs a[i]
END FOR
COMPUTE SUM by adding all values
CALCULATE AVG by dividing SUM by n
DISPLAY SUM and AVG
STOP

3. Pseudo code to find greatest of 2-number

READ A,B
IF (A>B)
DISPLAY “A is great”
ELSE
PRINT :B is great”
STOP

4. Pseudo code to find greatest of 3-number

READ A,B,C
IF (A>B)
IF (A>C)
DISPLAY “A is great”
ELSE IF (B>C)
PRINT “B is great”
ELSE
PRINT “C is great”
STOP

5. Pseudo code to find sum of even numbers between 0 and 100

SET sum=0
FOR (i=0;i<=100;i++)
CALCULATE sum=sum+i
EN FOR
PRINT sum
STOP

6. Pseudo code to find sum of n-even numbers

READ n
INITIALIZE i=0
SET sum=0
DO WHILE (i<n)
COMPUTE sum=sum+i
i =i+2
END DO
WRITE sum
STOP

7. Pseudo code to find factorial of a number


READ num
INITIALIZE fact=1
FOR (i=1;i<num;i++)
fact=fact*i
END FOR
OUTPUT fact
STOP

8. Pseudo code to find addition of 2-matrices

READ A[i][j], B[i][j]


INPUT row, col
FOR (i=0;i<row;i++)
FOR (j=0;j<col;j++)
Sum[i][j]=A[i][j]+B[i][j]
END FOR
END FOR
DISPLAY sum[i][j]
STOP

9. Pseudo code to find multiplication of 2-matrices

READ A[i][j], B[i][j]


INPUT row, col
FOR (i=0;i<row;i++)
FOR (j=0;j<col;j++)
SET C[i][j]=0
FOR (k=0;k<row;k++)
C[i][j]=c[i][j]+a[i][k]*b[k][j]
END FOR
END FOR
END FOR
DISPLAY C[i][j]
STOP

10. Pseudo code to find area of circle

READ radius
COMPUTE area=3.14*r*r
PRINT area
STOP

Important Question

2 marks
1. What is an algorithm?
2. What is flowchart? State its advantage.
3. What is pseudo code?
4. State advantage and disadvantage of an algorithm.
5. Differentiate program and algorithm.
6. List benefits and limitations of pseudo code.
7. State the benefits of drawing flowchart.
8. What are limitations of flowchart?
9. Write down the steps involved in writing a program.
10.List out characteristics of good program.
11.What are the characteristics of good algorithm?
12.Give basic symbols used in flowchart with its purposes.
13.List out design structure of flowchart.
14.Algorithm or pseudo code for any program.
15.Draw flowchart to find greatest of 3 numbers.

Detail

1. Draw and explain various symbols of flowchart and draw the flowchart to
add n-elements.

2. Draw flowchart and write algorithm to sort a list of numbers in ascending


order.

You might also like