Unit -1 Notes (1)
Unit -1 Notes (1)
1. INTRODUCTION TO COMPUTERS
1.1 Introduction
Computer System is an electronic data processing device which does the following:
A computer is an electronic machine that accepts information, stores it until the information is needed,
processes the information according to the instructions provided by the user, and finally returns the results to
the user.
The computer can store and manipulate large quantities of data at very high speed, but only disadvantage is
that a computer cannot think.
C - Common
O - Oriented
M - Machine
P - Particularly
U - Used For
T - Trade
E - Education And
R – Research
Definition
Computer is a fast operating electronic device which accepts and stores raw input data processes them
and produces output according to the instruction.
A computer is an electronic machine designed for performing calculations and controlling logical or
arithmetic operations.
A computer is an electronic device that performs various operations with the help of instructions to
achieve desire results.
Advantages
Disadvantages
What is Data?
Data is raw, unorganized facts that need to be processed. Data can be something simple and seems random
and useless until it is organized and processed.
The word ‘Data’ is derived from the plural form of Latin word ‘Datum’, which means ‘to give’.
Data is a collection of raw facts.
It May or may not be meaningful. For example ‘23’ is a meaningless data.
Input to any system may be treated as Data.
Data must be processed to understand.
Example: Statistics, numbers, characters, images.
What is Information?
The word ‘Information’ is derived from Latin word ‘Informare’, which means ‘to instruct’.
Information is the outcome derived after processing the data.
Information is always meaningful.
Output after processing the system is Information.
Information is already in understandable form, it may be processed further to make it more
understandable.
Example Reports, Knowledge.
Data Vs Information
Data Information
It is meaningless It is meaningful
1. Digital Computer
2. Analog Computer
3. Hybrid Computer
Digital Computer: A digital computer operates on digital data (0 and 1). It uses binary number system in
which there are only two digits 0 and 1.
Analog Computer: Analog Computer is a computing device that works on continuous range of values.
(between 0 and 1)It generally deals with physical variables such as voltage, pressure, temperature, speed, etc.
Hybrid Computer: A hybrid computer combines the desirable features of analog and digital computers.
Now-a-days analog-to-digital and digital-to-analog converters are used for transforming the data into suitable
form.
A computer can "do" only ONE thing. It can ADD 1's and 0's.
To perform all other mathematical functions the computer adds 1's and 0's in creative ways For example to
multiply 5 with 4 (5x4) a computer adds 5 four times (5+5+5+5)
Everything a computer does (Example playing video & audio, printing documents etc) is just addition of 1's
and 0's.
The computer performs has five basic operations and they are Input, Process, Output, Storing and Controlling.
1.Input:
It is the process of capturing or acquiring the information, or it is the process of accepting data or information,
2.Process:
It is the process of converting the input into output. It is the important part of any task
3.Output:
4.Storage:
It is the process of storing the data or information or instructions, so that the user can use it whenever
required.
5.Control:
It is the process of controlling and directing the sequence in which all the operations are to be performed.
1.2 Characteristics of Computers
Computer has spread to the nook and corner of this world .Each and every individual in this world is
somehow dependent on the computer
Speed: A computer is a very fast device. It can carry out instructions at a very high speed. It can perform in a
few seconds the amount of work that a human being can do in an entire year (Even if he work day and night
and does nothing else).. The speed of computer is calculated in MHz that is one million instructions per
second.
Accuracy: Accuracy of a computer is consistently high and the degree of accuracy of a particular computer
depends on the instructions and the type of processor. But for a particular computer, each and every
calculation is performed. For example, the computer accurately gives the result of division of any number up
to 10 decimal points.
Versatility: Versatility is one of the salient features of the computer. Versatility is nothing but the Multi-
processing ability of computer. One moment, a computer will analyze the results of particular examination,
the next moment it will be busy preparing electricity bills, and in between it may be help to search an
important letter in seconds.
It can perform different types of tasks with same speed and accuracy.
Briefly, a computer is capable of performing almost any task provided that the task can be reduced to a series
of logical steps.
Reliability: Computer has a high level for reliability. Thus computers never make mistakes of their own.
If it makes a mistake it means that a human might have given a wrong instruction.
A computer has an amazing Power of Remembering. It can remember a data for an infinite time, unless it is
intentionally deleted by the user
A computer can store and recall any amount of information because of its secondary storage capability. Every
piece of information can be retaining as long as desired by the user. Even after several years, the information
recalled will be as accurate as on the day when it was fed to the computer.
Diligence: The computer is just a machine, does not suffer from the human characters such as tiredness. It can
work for days together without getting any symptoms of tiredness it does not lose concentration even after
working continuously for a long time.
This characteristic is especially useful for those jobs where same tasks are done again and again. It can
perform long and complex calculations with same speed and accuracy from the start till the end.
For example an ATM machine will be working nonstop for years together with same speed and accuracy
Storage: The computers have a lot of storage devices which can store a tremendous amount of data. Data
storage is an important aspect of the computer.
Second storage devices like floppy disk can store a large amount of data permanently. The secondary storage
can range from 1Mega Byte (a floppy disk) to 1Tera Byte(External Hard Disk Drive).The secondary storage
devices can be easily attached and detached whenever needed.
Resource Sharing: In the initial stages of development, computer used to be an isolated machine. With the
tremendous growth in computer technologies, today's computers have the capability to connect with each
other. This has made the sharing of costly resources like printers possible. Apart from device sharing, data
and information can also be shared among groups of computers, thus creating a large information and
knowledge base.
No I.Q: A computer is a magical device. It can only perform tasks that a human being can. The difference is
that it performs these tasks with unthinkable speed and accuracy.
It possesses no intelligence of its own. Its I.Q is zero. It can only perform what is programmed to do. Hence,
only the user can determine what tasks a computer will perform.
Making a computer to think (Artificial intelligence) has been now a wide area of research.
1.3.1 Introduction
Generation in a computer terminology means the change in the technology that is being used in a computer.
Initially the term generation was used to distinguish between varying hardware technologies. But nowadays,
generation includes both hardware and software, which together make up an entire computer system.
There are totally five computer generations known till date. Each generation has been discussedin detail along
with their time period, characteristics.
Colossus was the first electronic computer of this Generation. It’s every aspect was kept secret by
British Government.
In 1945, Von Neumann Architecture was introduced. Eckert and Mauchley began working on
EDVAC (Electronic Discrete Variable Automatic Computer) but it never completed. Later Von
Neumann developed his own EDVAC (IAS machine).
In 1946, the development of ENIAC (Electronic Numerical Integrator and Computer), which was
started in 1943, was completed.
In 1954, first version of FORTRAN (Formula Translator) was published by IBM.
Features:
Advantages:
Disadvantages:
Unreliable
Very costly
EDVAC
UNIVAC
IBM-701
IBM-650
Transistors increased the processing power of computer and decreased the size, cost and power usage as well.
Use of transistors
Advantages
It is very costly
IBM 1620
IBM 7094
CDC 1604
CDC 3600
UNIVAC 1108
The invention of silicon ICs (Integrated Circuits) allowed dozens of transistors to be put on a single chip.
They used magnetic disks as memory devices but later they were replaced by semiconductor memories.
Multiprogramming.
The computers were more powerful and smaller than previous generations.
Some of the programming languages built in this generation are: ada, PASCAL, BCPL,
SHRDLU, FORTRAN 66 and 77, SEQUEL (nowadays it is called SQL)
Intel introduced its microprocessors - Intel 4004, Intel 8080, 8086, 8088.
Examples of third generation of computer are Apple computers, CDC's Cyber- 175 and PDC
series, STAR 1100 etc.
Supported multiprogramming
Advantages:
More reliable
Smaller size
Faster
Lesser maintenance
Disadvantages:
Still costly
IBM-360 series
Honeywell-6000 series
IBM-370/168
TDC-316
The VLSI technology allowed millions of transistors to be fabricated on a single chip. This high density of
fabrication directly affected the size and sped of the machine.
With heavy drop in price, it become possible for single individual to have his/her own computer.
Pipeline processing
Advantages
Very cheap
DEC 10
STAR 1000
PDP 11
CRAY-1(Super Computer)
CRAY-X-MP(Super Computer)
These computers will use ULSI (Ultra Large Scale Integration) chips.
These generation computers have been focusing on developing intelligent computers which can
have vision, learning ability, object recognition and synthesis ability, natural language
understanding ability.
The input and output of the computes will be in the form of speech and graphic
These computers use optic fiber technology to handle Artificial Intelligence, expert systems, robotics
etc. These computers have very high processing speeds and are more reliable.
All the Higher level languages like C and C++, Java, .Net etc. are used in this generation.
Robotics
Neural networks
Game Playing
ULSI technology
All disadvantages of the previous generation computers have been replace by the fifth generation computes
Desktop
Laptop
Notebook
UltraBook
ChromeBook
MEMORY CAPACITY
20 KB 128KB 1MB 1 GB 1 TB
MEASURED IN
BEYOND
PICOSECONDS
MEASURED IN AND MIPS
PROCESSING SPEED 300IPS 300IPS 1MIPS
NANO SECONDS (MILLION OF
INSTRUCTION
PER SECOND)
HIGH LEVEL
PROGRAMMING ASSEMBLY ALL LATEST
LANGAUGAE(FORTR
LANGAUAGES C, C++ C , C++ , JAVA LANGUAGES
AN , ALGOL)
LESS COMPARE TO
POWER CONSUMED HIGH LESS LESS LESS
1ST GEN.
The digital computers that are available nowadays vary in their sizes and types. The computers are broadly
classified into four categories based on their size and type
(1) Microcomputers,
(2) Minicomputers,
(4) Supercomputer.
A microprocessor is a processor whose components such as input, output and CPU are present on a
single integrated circuit chip.
Including power supply, connecting cables, appropriate peripherals (keyboard, monitor, printer,
others) and other software programs forms a complete micro computer system.
These are normally single microprocessor systems (single – user systems) designed for small
applications.
It is mainly used in offices, homes, shops, etc.
They brought revolution in the history of computers.
They are also known as Personal Computers.
They are cheap and user friendly.
The main components are Monitor, CPU, Keyboard, Mouse, Speakers, Modem and Printer.
Mini computers are larger than the micro computers and are more powerful in terms of processing
power.
Mini computers are mainly multiprocessor systems where many users simultaneously work on the
systems. It is capable of supporting from 4 to about 200 simultaneous users.
Mini computers can be used for interactive applications in industries, research organizations, colleges
and universities.
They are used for data processing also.
Disadvantages
They have less memory & storage capacity than mainframe computers.
1.4.1.3 Mainframe Computer
Advantages
Disadvantages
Super computers are specially designed to maximize the numbers of FLOPS (Floating Point Operation
per Second)
A Super Computer has the highest processing speed
It is suitable for solving scientific and engineering problems.
They are huge computers installed in space centers, nuclear power stations etc.
They are used for performing complex mathematical calculations.
They are used for weather forecasting, animation graphics etc
Advantages
Disadvantages
These are designed and constructed to cater almost all the needs of the society.
They are able to perform according to the programs created to meet different needs.
These can be used for a variety of tasks from financial, accounting to mathematical calculations.
They are also flexible and can be used to work on business and scientific problems.
Introduction
The analog computer works on the supply of continuous electrical signals. The display is also
continuous and its output is in the form of graphs.
Computations are carried out with physical quantities such as voltage, length, current, temperature etc.
the devices measuring such quantities are called analog devices.
The analog computer operates by measuring instead of counting.
The advantage is that all calculations take place parallelly and hence it is very fast.
Example:
Thermometer is the example of analog computers because it measures the length of a mercury column
continuously
A traditional clock is the example of analog computers because the needle of clock covers the distance
of dial continuously.
Weight machine and Speedo meter are other examples of analog computers.
Introduction
In digital computer, numeric and non - numeric information are represented as strings of digits.
The data is represented by binary notation in the form of 0’s and 1’s.
Examples
Digital watch, digital petrol stations and the computer, which we use nowadays, are the examples of
digital computers
Introduction
In a hybrid computer, the measuring functions are performed by the analog while control and logic
functions are digital in nature.
Weather monitoring systems and devices in intensive care units of the hospitals are examples of
hybrid computers.
Example:
In ICU (Intensive care unit) of a hospital hybrid computers are used. These computers analog quality
controls the temperature of the room digital quality informs the doctor about the blood pressure,
temperature and physical status of the patient.
In Cement factory a hybrid computer is used where all calculations are performed by the digital
computers; and actions like increase of material are performed by the analog computers.
Analog Digital
Analog signal is a continuous signal which Digital signals are discrete time signals
Signal:
represents physical measurements. generated by digital modulation.
Waves: Denoted by sine waves Denoted by square waves
Uses continuous range of values to represent Uses discrete or discontinuous values to
Representation:
information represent information
Analog Digital
Computers, CDs, DVDs, and other digital
Example: Human voice in air, analog electronic devices.
electronic devices.
Analog technology records waveforms as they Samples analog waveforms into a limited set of
Technology:
are. numbers and records them.
Data Subjected to deterioration by noise during Can be noise-immune without deterioration
transmissions: transmission and write/read cycle. during transmission and write/read cycle.
Response to Less affected since noise response are analog in
More likely to get affected reducing accuracy
Noise: nature
Flexibility: Analog hardware is not flexible. Digital hardware is flexible in implementation.
Can be used in analog devices only. Best Best suited for Computing and digital
Uses:
suited for audio and video transmission. electronics
Applications: Thermometer PCs, PDAs
There is no guarantee that digital signal
Analog signal processing can be done in real processing can be done in real time and
Bandwidth:
time and consumes less bandwidth. consumes more bandwidth to carry out the same
information.
Memory: Stored in the form of wave signal Stored in the form of binary bit
Power: analog instrument draw large power digital instrument draw only negligible power
Cost: low cost and portable cost is high and easily not portable
Impedance: Low high order of 100mega ohm
analog instruments usually have a scale which
digital instruments are free from observational
Errors: is cramped at lower end and give considerable
errors like parallax and approximation errors
observational errors
1.5 Basic Computer Organization
Computer organization is a study of a Computer Architecture. E.g. Memory, Registers, RAM, ROM, CPU,
ALU, 16 bit/32 bit/64 bit architectures.
1.5.1 Introduction
A Computer Performs basically five major operations or functions The five basic operations of a Computer
System
1. Inputting.
The process of entering data and instructions into the computer system.
2. Storing.
Saving data and instructions to make them readily available for processing whenever required.
3. Processing.
Performing arithmetic operations (add, subtract, multiply, divide, etc.) or logical operations
(Comparisons like equal to, less than, greater than, etc.) on data to convert them into useful
Information.
4. Outputting.
The process of producing useful information or results for the user via printed report or visual display.
5. Controlling.
Directing the manner and sequence in which all of the above operations are performed.
This is the process of entering data and programs in to the computer system. You should know that
computer is an electronic machine like any other machine, which takes input as raw data and performs
some processing giving out processed data or information.
Therefore, the input unit takes data from us to the computer in an organized manner for processing.
Input devices are electromechanical devices that allow the user to feed information into the computer
for analysis, storage and giving commands to the Central Processing Unit.
Data and instructions are entered into the memory of a computer through input devices.
It captures information and translates it into a form that can be processed by the central processing
unit.
Computer accepts input in either manually or directly.
In case of manual data entry, the user enters the data into the computer by hand. For example, by using
keyboard and mouse.
In case of direct entry, information is fed into the computer automatically from a source document
(like barcode).
Some of the important input devices are:
Keyboard, Mouse, Light pen, Trackball, Joystick, Scanner etc.
CPU is the abbreviation for central processing unit. Sometimes it is referred as the central processor,
but more commonly it is called processor,
The CPU is the brains of the computer where most calculations take place.
In terms of computing power, the CPU is the most important element of a computer system.
Popular CPU Manufacturers are Intel, AMD.
Computer CPU’s (processors) is composed of thousands of transistors.
Transistors are tiny, nearly microscopic bits of material that will block electricity when the electricity is only
a weak charge, but will allow the electricity pass through when the electricity is strong enough.
Control Unit (CU): Controls the operation of the CPU and hence the computer.
Arithmetic and Logic Unit (ALU): Performs computer’s data processing functions.
CPU Interconnection: It provides for communication among the control unit, ALU, and register.
The control unit directs the entire computer system to carry out stored program instructions.
The control unit must communicate with both the arithmetic logic unit (ALU) and main memory.
The control unit instructs the arithmetic logic unit that to perform logical or arithmetic operation.
The control unit co-ordinates the activities of the other units , peripherals and auxiliary storage devices
linked to the computer
8 Bits = 1 Byte
1024 Bytes = 1 KB (Kilo Byte)
1024 KB = 1 MB (Mega Byte)
1024 MB = 1 GB(Giga Byte)
1024 GB = 1 TB (Terra Byte)
1024 TB = 1 PB (Peta Byte)
1024 PB= 1 EB (Exa Byte)
1024 EB = 1 ZB (Zetta Byte)
1024 ZB = 1 YB (Yotta Byte)
1024 YB = 1 (Bronto Byte)
1024 BB = 1 (Geop Byte)
Devices used to get the response or result of a process from the computer is called output devices.
An output device is an electromechanical device, which converts machine-readable information into
human-readable form.
The basic functioning of output device is just the opposite of the input device, that is, the data are 'fed
into' the computer system through the input device, while the output is 'taken out' from the computer
through the output device.
The output, which comes out from the CPU, is in the form of digital signals.
The output devices display the processed information by converting them into graphical, alphanumeric
or audio-visual form.
The output devices are classified into hard copy and soft copy output devices.
Printers, plotters, and microfilms are the most commonly used hard copy output devices while monitors, voice
response systems, projectors, electronic whiteboards, and headphones and headsets are some commonly used
soft copy output devices.
1.6.1 Introduction
Note : Positional Vs Non-Positional : In a positional number system, the position has significance and
values. Example: Decimal number system. In non-positional number systems, the position of the
number isn't a determining factor. Example: roman numerals.
1.6.2 Types of Number System
Types
1. Binary System
Introduction to Binary
The decimal value of "T" is 84, and 84 can be represented in binary form as 01010100
0 (0 * 20)order of 1
1 (1* 21)order of 2
0 (0* 22)order of 4
0 (0 * 23) order of 8
1 (1 * 24) order of 16
(1* 16) + (0 * 8) + (0 * 4) +( 1 * 2) + (0 * 1)
16 + 0 + 0 + 2 + 0
(18)10
2 (2 * 80) order of 1
4096 + 0 + 320 + 56 + 2
(4474)10
The Hexadecimal or base 16 number system is important to programmers because it's a shorthand
way of writing out and inputting binary.
"hex" means six(6), and "dec" means ten(10),
The word hexadecimal means six and ten i.e. sixteen.
The base or radix of the hexadecimal number system is 16.
There are sixteen (16) symbols in a hexadecimal number system.
The symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and A, B, C, D, E, and F.
A =10;
B=11;
C=12;
D=13;
E=14,
F=15.
Note: the numbers 10-15 in a Hexadecimal number system must be written as A-F respectively.
Example:
2 (2* 161)order of 16
65536 + 0 + 2560 + 32 + 11
(68139)10
Instead of representing 11 as B, if we represent it as 11, we would have some trouble in reading the
value of the Hexadecimal.
For Example: Instead of writing 1B5, if we write as1115, then it will lead to error. i.e. when we
convert into decimal 437 will be interpreted as 4373.
1.6.7 Conversion : Natural Number Conversion
Conversion is nothing but converting the numbers in one base to another base:
(Number)x =(Number)y
There are certain rules called as conversion rules that tells us how to convert values form one base to
another base.
There are three different strategies in converting a number form one base to another base.
A number can be converted from decimal to binary using repeated division method.
Repeated Division
The following are the steps in converting a decimal number to a binary number.
Step1 : Divide the number by2 (whenever you divide a number by 2, you will get either
0 or 1 as remainder).
Step 2 : Write down the remainder one by one from right to left.(right most digit of a
number is called Least Significant Bit and left most digit of a number is called
Most Significant Bit)
Step3: If the Quotient becomes zero go to Step4, otherwise go to step1.
Step4 : The number you obtain by writing down the remainder is the converted binary number.
Example of Repeated Division
56 ÷2= 28 0 000000
28 ÷2= 14 0 0000000
14 ÷2= 7 0 00000000
7 ÷2= 3 1 100000000
3 ÷2= 1 1 1100000000
1 ÷2= 0 1 11100000000
0 Done.
(1792)10 (11100000000)2
Repeated Division:
The following are the steps in converting a decimal number to an octal number.
Step1 : Divide the number by 8(whenever you divide a number by 8, you will get 0,
1, 2, 3,4,5,6 or 7 as remainder).
Step 2: Write down the remainder one by one from right to left.
Step3: If the Quotient becomes zero go to Step4, otherwise go to step1.
Step4 : The number you obtain by writing down the remainder is the converted octal
number.
Example of Repeated Division:
224 ÷8= 28 0 00
28 ÷8= 3 4 400
3 ÷8= 0 3 3400
0 Done.
(1792)10 (3400)8
Repeated Division:
The following are the steps in converting a decimal number to a Hexadecimal number.
Step1 : Divide the number by 16 (whenever you divide a number by 16, you will get 0, 1,
2, 3,4,5,6,7,8,9,A(10),B(11),C(12),D(13),E(14),F(15) as remainder).
Step 2 : Write down the remainder one by one from right to left.
Step3 : If the Quotient becomes zero go to Step4, otherwise go to step1.
Step4 : The number you obtain by writing down the remainder is the converted
Hexadecimal number.
Example of Repeated Division:
1792 ÷ 16 = 112 0 0
112 ÷ 16 = 7 0 00
7 ÷ 16 = 0 7 700
0 done.
(1792)10 (700)16
2564 ÷ 16 = 160 4 4
160 ÷ 16 = 10 0 04
7 ÷ 16 = 0 10 A04
0 Done.
(2564)10 (A04)16
Note: when converting from decimal to hexadecimal if the remainder is greater than 9, the
corresponding hexadecimal equivalent should be written.
1.6.7.1.4 General Algorithm for Converting Decimal Number to Other Base Number
Repeated Division
The following are the steps in converting a decimal number to another Base number.
Step1 : Divide the number by B (whenever you divide a number by B, you will get a
number between 0 and B-1 as a remainder).
Step 2 : Write down the remainder one by one from right to left.
Step3 : If the Quotient becomes zero go to Step4, otherwise go to step1.
Step4 : The number you obtain by writing down the remainder is the converted Base B number.
Example:
358 ÷5= 71 3 32
71 ÷5= 14 1 132
14 ÷5= 2 4 4132
2 ÷5= 0 2 24132
(1792)10 (24132)5
A number can be converted from binary number to Decimal number using positional notation method.
Algorithm
Example 1
1 X 20 = 1
2. Move to next rightmost digit, if there is no digit to the right of the binary number then go to Step 6.
3. Multiply this rightmost digit value with 2i, where i=1, initially.
0 X 21 =0
1 X 22 =4
1 X 23 =8
i=1
i=2
i=3
5. Go to Step2
0+4+8 = 12
12+1=13
(1101)2 (13)10
Example 2:
1 0 1 X 20 1X1 1
0 1 0 X 21 0X2 0
1 2 1 X 22 1X4 4
0 3 0 X 23 0X8 0
1 4 1 X 24 1 X 16 16
1 5 1 X 25 1 X 32 32
1 6 1 X 26 1 X 64 64
1 + 0 + 4 + 0 + 16 + 32 + 64 = (117)10
A number can be converted from Octal number to Decimal number using positional notation method.
Algorithm
Example 1
5 X 80 = 5
2. Move to next rightmost digit, if there is no digit to the right of the Octal number then go to
Step 6.
3. Multiply this rightmost digit value with 8i, where i=1, initially.
2 X 81 =16
0 X 82 =0
1 X 83 =512
i=1
i=2
i=3
5. Go to Step 2
6. Add every value obtained in Step 3.
16+0+512 = 528
528+5=533
Example 2
(20126)8 to Decimal
Moving from right most digits ,we right the value one by one from top to bottom
6 0 6 X 80 6X1 6
2 1 2 X 81 2X8 16
1 2 1 X 82 1 X 64 64
0 3 0 X 83 0 X 512 0
2 4 1 X 84 2 X 4096 8192
6 + 16 + 64 + 0 + 8192 = (8278)10
(20126)8 (8278)10
A number can be converted from Hexa decimal number to Decimal number using positional notation method.
Algorithm
2. Move to next rightmost digit, if there is no digit to the right of the Hexadecimal number then
go to Step 6.
3. Multiply this rightmost digit value with 16i, where i=1, initially.
5. Goto Step2
7. Add the Value obtained in Step 6 with the value obtained in Step2
Example
1 X160 = 1
2. Move to next rightmost digit, if there is no digit to the right of the Hexadecimal number
then Go to Step 6.
3. Multiply this rightmost digit value with 16i, where i=1, initially.
i=1
i=2
i=3
5. Go to Step 2
40960+2816+192 = 43968
43968+1=43969
(43969)10
(ABC1)16 (43969)10
Example 2:
(10E7)16 to Decimal
Moving from right most digits ,we right the value one by one from top to bottom
7 0 7 X 160 7X1 7
E 1 14 X 161 14 X 16 224
0 2 0 X 162 0 X 256 0
1.6.7.2.4 General Formula for converting a number from any base to the Decimal
number
Where N is the number of digits in the given number and B is the base of the given number
Example
1 0 1 X 50 1X1 1
3 1 3 X 51 3X5 15
4 2 4 X 52 4 X 125 500
2 3 2 X 53 2 X 625 1250
(2431)5 (1766)10
There are two steps that are to be followed in converting a number form base X to base Y.
First convert the Base X number to an equivalent Decimal number using Positional Notation method.
Then convert the Decimal number to Base Y number using Repeated Division method
1.6.7.3.1 Binary to Octal
There are two steps that are to be followed in converting a number form Binary to Octal.
First convert the Binary number to an equivalent Decimal number using Positional Notation method.
Then convert the Decimal number to Octal number using Repeated Division method
Example:
(1011001)2 (X)8
(1011001)2 (Y)10
1 0 1 X 20 1X1 1
0 1 0 X 21 0X2 0
0 2 0 X 22 0X4 0
1 3 1 X 23 1X8 8
1 4 1 X 24 1 X 16 16
0 5 0 X 25 0 X 32 0
1 6 1 X 26 1 X 64 64
1 + 8 + 16 + 64 = (89)10
(89)10 (x)8
89 ÷8= 11 1 1
11 ÷8= 1 3 31
1 ÷8= 0 1 131
0 Done.
(1011001)2 (131)8
There are two steps that are to be followed in converting a binary number to Hexadecimal number.
First convert the Binary number to an equivalent Decimal number using Positional Notation method.
Then convert the Decimal number to its equivalent Hexadecimal number using Repeated Division
method.
Example:
(1011001)2 (X)16
(1011001)2 (Y)10
1 0 1 X 20 1X1 1
0 1 0 X 21 0X2 0
0 2 0 X 22 0X4 0
1 3 1 X 23 1X8 8
1 4 1 X 24 1 X 16 16
0 5 0 X 25 0 X 32 0
1 6 1 X 26 1 X 64 64
1 + 8 + 16 +64 = (89)10
(89)10 (x)16
5 ÷ 16 = 0 5 59
0 Done.
There are two steps that are to be followed in converting an Octal number to Binary number.
First convert the Octal number to an equivalent Decimal number using Positional Notation method.
Then convert the Decimal number to its equivalent Binary number using Repeated Division method.
Example:
(632)8 ( ? )2
(632)8(Y)10
2 0 2 X 80 2X1 2
3 1 3 X 81 3X8 24
6 2 6 X 82 6 X 64 384
2 + 24 + 384 = (410)10
(410)10 (X)2
25 ÷2= 12 1 11010
12 ÷2= 6 0 011010
6 ÷2= 3 0 0011010
3 ÷2= 1 1 10011010
1 ÷2= 0 1 110011010
0 Done.
There are two steps that are to be followed in converting an Octal number to Hexa Decimal number.
First convert the Octal number to an equivalent Decimal number using Positional Notation method.
Then convert the Decimal number to its equivalent Hexadecimal number using Repeated Division
method.
Example:
(632)8 (X)16
(632)8(Y)10
2 0 2 X 80 2X1 2
3 1 3 X 81 3X8 24
6 2 6 X 82 6 X 64 384
2 + 24 + 384 = (410)10
Step 2: Decimal to Hexadecimal by Repeated Division method
(410)10 (x)16
410 ÷ 16 = 25 10 A
25 ÷16 = 1 9 9
1 ÷ 16 = 0 1 19A
0 Done.
There are two steps that are to be followed in converting a Hexadecimal to Binary number.
First convert the Hexadecimal number to an equivalent Decimal number using positional notation
method.
Then convert the Decimal number to its equivalent Binary number using repeated division method.
Example:
(2BD)16 ( X )2
(2BD)16(X)10
D 0 13 X 160 13 X 1 13
87 ÷2= 43 1 1101
43 ÷2= 21 1 11101
21 ÷2= 10 1 111101
10 ÷2= 5 0 0111101
5 ÷2= 2 1 10111101
2 ÷2= 1 0 010111101
1 ÷2= 0 1 1010111101
0 Done.
There are two steps that are to be followed in converting a Hexadecimal to Octal number.
First convert the Hexadecimal number to an equivalent Decimal number using Positional Notation
method.
Then convert the Decimal number to its equivalent Octal number using Repeated Division method.
Example:
(2BD)16 (X)8
(2BD)16(X)10
Value Value of i Value X 16i
D 0 13 X 160 13 X 1 13
(701)10 (x)2
701 ÷8= 87 5 5
87 ÷8= 10 7 75
10 ÷8= 1 2 275
1 ÷8= 0 1 1275
0 done.
1. Integer part
2. Fraction part.
Example : 24.41
Integer part = 24
Integer part of the decimal value can be converted to other base B by using repeated division method.
The fraction part of the decimal value can be converted by using the steps below.
Procedure
Note: The value of x can be chosen according to the precision. If you want two points after the decimal
point X, can be chosen as 2 or if you want five points after the decimal X, can be chosen as 5.
Example 1
(15.125)10 (Y.Z)10
Y Integer Part
Z Fraction Part
(15)10 (Y)2
15 ÷2= 7 1 1
7 ÷2= 3 1 11
3 ÷2= 1 1 111
1 ÷2= 0 1 1111
0 done.
(15)10 (1111)2
(0.125)10 (Z)2
Fraction part Fraction part X base B Multiplied Value Integer part Binary result
0.0 Done
Stop
(0.125)10 (.001)2
Note: Here after the third step the fraction part became Zero and hence we stopped with 3 digits after
decimal point.
(15.125)10 (1111.001)2
Example 2
(11.235)10 (Y.Z)2
Y Integer Part
Z Fraction Part
(11)10 (Y)2
11 ÷2= 5 1 1
5 ÷2= 2 1 11
2 ÷2= 1 0 011
1 ÷2= 0 1 1011
0 Done.
(11)10 (1011)2
(0.235)10 (Z)2
Fraction part Fraction part X base B Multiplied Value Integer part Binary result
Stop
(0.235)10 (.00111)2
Note: Here the value of X is chosen to be 5 and hence we stopped with 5 digits after decimal point.
(11.235)10 (1011.00111)2
Example 1
(23.078125)10 (Y.Z)8
Y Integer Part
Z Fraction Part
Converting Integer Part.
(23)10 (Y)8
23 ÷8= 2 7 7
2 ÷8= 0 2 27
0 done.
(23)10 (27)2
(0.078125)10 (Z)8
Fraction part Fraction part X base B Multiplied Value Integer part Octal result
0.0 Done
Stop
(0.078125)10 (.05)8
Note: Here after the Second step the fraction part became Zero and hence we stopped with 2 digits
after decimal point.
(23.078125)10 (27.05)8
Example 2
(23.54)10 (Y.Z)8
Y Integer Part
Z Fraction Part
Converting Integer Part.
(23)10 (Y)8
23 ÷8= 2 7 7
2 ÷8= 0 2 27
0 Done.
(23)10 (27)2
(0.54)10 (Z)2
Fraction part Fraction part X base B Multiplied Value Integer part Octal result
Stop
(0.54)10 (.3424)2
Note: Here the value of X is chosen to be 4 and hence we stopped with 4 digits after decimal point.
(23.54)10 (27.3424)8
Example 1
(163.09375)10 (Y.Z)16
YInteger Part
Z Fraction Part
(163)10 (Y)16
163 ÷16 = 10 3 3
10 ÷16 = 0 10 A
0 Done.
(163)10 (A3)16
(0.09375)10 (Z)16
Fraction part Fraction part X base B Multiplied Value Integer part Hexadecimal
result
0.5 0.5 X 16 = 8 8 18
0.0 Done
Stop
(0.09375)10 (.18)16
Note: Here after the Second step the fraction part became Zero and hence we stopped with 2 digits
after decimal point.
(163.09375)10 (A3.18)16
Example 2
(163.48)10 (Y.Z)16
YInteger Part
Z Fraction Part
(163)10 (Y)16
163 ÷16 = 10 3 3
10 ÷16 = 0 10 A
0 Done.
(163)10 (A3)16
(0.48)10 (Z)16
Fraction part Fraction part X base B Multiplied Value Integer part Hexadecimal
result
Stop
(0.48)10 (.7AE1)16
Note: Here the value of X is chosen to be 4 and hence we stopped with 4 digits after decimal point.
(163.48)10 (A3.1A7E)16
Where ,
The only difference is that in the integer part, the value of i will be positive whereas in the fraction part the
value of i will be negative.
(1111.001)2 (Y.Z)10
1 0 1 X 20 1X1 1
1 1 1 X 21 1X2 2
1 2 1 X 22 1X4 4
1 3 1 X 23 1X8 8
1 +2 + 4 + 8= (15)10
0 1 1 X 2-2 1 X 0.25 0
1 2 1 X 2-3 1 X 0.125 1
(1111.001)2 (15.125)10
(27.05)8(Y.Z)10
7 0 7 X 80 7X1 7
2 1 2 X 81 2X8 16
7 + 16 = (23)10
0 0 0 X 8-1 0 X 0.125 0
0 + 0.078125 = (0.78125)10
(27.62)8 (23.078125)10
(A3.18)16(Y.Z)10
Integer Part: (A3)16(Y)10
3 0 3 X 160 3X1 3
A 1 10 X 161 10 X 16 160
160 + 3 = (163)10
(A3.18)8 (163.09375)10
Whenever we have to convert the value from one base to another base, first we have to convert into decimal,
then we have to convert from decimal to the other base
Example:
(25.26)7 (Y.Z)5
5 0 5 X 70 5X1 5
2 1 2 X 71 2X7 14
5 + 14 = (19)10
(25.26)7 (19.408162)10
19 ÷5= 3 4 4
3 ÷5= 0 3 34
0 Done.
(19)10 (34)5
Fraction part Fraction part X base B Multiplied Value Integer part Hexa decimal
result
Stop
(0.408162)10 (0.2010)5
(25.26)7 (34.2010)5
1. Group binary digits into sets of four, starting with the least significant (rightmost) digits.
2. If the group does not have four digits then pad zero to the left.
3. Write the corresponding hexadecimal value for each group.
Example 1:
(1110010101101101)2 = (?)16
(1110010101101101)2 = (E56D)16
Example 2:
(1011001011)2 = (?)16
2 C B
(1011001011)2 = (2CB)16
Binary Hexadecimal
1. Group binary digits into sets of three, starting with the least significant (rightmost) digits.
2. If the group does not have three digits then pad zero to the left.
3. Write the corresponding octal value for each group.
Example 1:
(111001011)2 = (?)8
7 1 3
(111001011)2 = (713)8
Example 2:
(1110010101101101)2 = (?)8
1 6 2 5 5 5
(1110010101101101)2 = (16255)8
Binary Octal
Binar
Octal Binary Octal
y
000 0 100 4
001 1 101 5
010 2 110 6
011 3 111 7
Write down the binary equivalent(three digits) of each octal digit starting from right end and moving
towards left end
Example:
(713)8 = (?)2
7 1 3
(713)8 = (111001011)2
Write down the binary equivalent (four digits) of each hexadecimal digit starting from right end and
moving towards left end.
Example
(E56D)16 = (?)2
E 5 6 D
(E56D)16 = (1110010101101101)2
Example:
Convert 345 octal into hex.
Step 1: (345)8 = (?)2
3 4 5
011 100 101
(345)8 = (011100101)2
Step 2: (011100101)2 = (?)16
Example:
Convert A2DE Hexadecimal into Octal.
A D 2 E
(AD2E)16 = (1010110100101110)2
1 2 6 4 5 6
(1010110100101110)2 = (126456)8
Hex Oct Bin Dec Hex Oct Bin Dec Hex Oct Bin Dec Hex Oct Bin
Dec
Dec Hex Oct Bin Dec Hex Oct Bin Dec Hex Oct Bin Dec Hex Oct Bin
128 80 200 10000000 144 90 220 10010000 160 A0 240 10100000 176 B0 260 10110000
129 81 201 10000001 145 91 221 10010001 161 A1 241 10100001 177 B1 261 10110001
130 82 202 10000010 146 92 222 10010010 162 A2 242 10100010 178 B2 262 10110010
131 83 203 10000011 147 93 223 10010011 163 A3 243 10100011 179 B3 263 10110011
132 84 204 10000100 148 94 224 10010100 164 A4 244 10100100 180 B4 264 10110100
133 85 205 10000101 149 95 225 10010101 165 A5 245 10100101 181 B5 265 10110101
134 86 206 10000110 150 96 226 10010110 166 A6 246 10100110 182 B6 266 10110110
135 87 207 10000111 151 97 227 10010111 167 A7 247 10100111 183 B7 267 10110111
136 88 210 10001000 152 98 230 10011000 168 A8 250 10101000 184 B8 270 10111000
137 89 211 10001001 153 99 231 10011001 169 A9 251 10101001 185 B9 271 10111001
138 8A 212 10001010 154 9A 232 10011010 170 AA 252 10101010 186 BA 272 10111010
139 8B 213 10001011 155 9B 233 10011011 171 AB 253 10101011 187 BB 273 10111011
140 8C 214 10001100 156 9C 234 10011100 172 AC 254 10101100 188 BC 274 10111100
141 8D 215 10001101 157 9D 235 10011101 173 AD 255 10101101 189 BD 275 10111101
142 8E 216 10001110 158 9E 236 10011110 174 AE 256 10101110 190 BE 276 10111110
143 8F 217 10001111 159 9F 237 10011111 175 AF 257 10101111 191 BF 277 10111111
Dec Hex Oct Bin Dec Hex Oct Bin Dec Hex Oct Bin Dec Hex Oct Bin
192 C0 300 11000000 208 D0 320 11010000 224 E0 340 11100000 240 F0 360 11110000
193 C1 301 11000001 209 D1 321 11010001 225 E1 341 11100001 241 F1 361 11110001
194 C2 302 11000010 210 D2 322 11010010 226 E2 342 11100010 242 F2 362 11110010
195 C3 303 11000011 211 D3 323 11010011 227 E3 343 11100011 243 F3 363 11110011
196 C4 304 11000100 212 D4 324 11010100 228 E4 344 11100100 244 F4 364 11110100
197 C5 305 11000101 213 D5 325 11010101 229 E5 345 11100101 245 F5 365 11110101
198 C6 306 11000110 214 D6 326 11010110 230 E6 346 11100110 246 F6 366 11110110
199 C7 307 11000111 215 D7 327 11010111 231 E7 347 11100111 247 F7 367 11110111
200 C8 310 11001000 216 D8 330 11011000 232 E8 350 11101000 248 F8 370 11111000
201 C9 311 11001001 217 D9 331 11011001 233 E9 351 11101001 249 F9 371 11111001
202 CA 312 11001010 218 DA 332 11011010 234 EA 352 11101010 250 FA 372 11111010
203 CB 313 11001011 219 DB 333 11011011 235 EB 353 11101011 251 FB 373 11111011
204 CC 314 11001100 220 DC 334 11011100 236 EC 354 11101100 252 FC 374 11111100
205 CD 315 11001101 221 DD 335 11011101 237 ED 355 11101101 253 FD 375 11111101
206 CE 316 11001110 222 DE 336 11011110 238 EE 356 11101110 254 FE 376 11111110
207 CF 317 11001111 223 DF 337 11011111 239 EF 357 11101111 255 FF 377 11111111
A program consists of sequence of instructions that will be processed by the computer program to perform
the specified task. There is lot of planning and analysis that should be carried out in order to write a program.
Writing a program requires a lot of logical thinking.
Programmers follow 80-20 rule which means that in order to write 20% of coding the programmer should
plan for 80%.
Whenever programmers develop software applications, they follow an organized plan, or methodology that
breaks the process into a series of tasks. In order to write a program, the programmer should identify the
requirements of the program such as the logic, instructions and data.
What is logic?
Logic is a just an idea or a blue print for a part of a program which consists of set of instructions to solve the
given problem. Logic of the program consists of the statements which will be then converted into
programming language statements that will be executed by the computer in order to solve the problem. The
logic for solving a problem is developed and then embedded in a program by following the rules of writing a
program.
Logical thinking is essential for every programmer. Anyone who is writing and learning a program should be
capable of thinking logically. Thinking logically is a key to develop programs. Every program is made up of
logics, so one should have logical thinking capability in order to develop logic for certain program.
Every programmer needs to think logically in order to develop logic for a program but the problem is to find
out how to think logically. So in order to think logically we should learn how logic will work and how to
develop logic for a program. To develop logic for a program one should be capable of thinking logically. Only
a logical thinker can be capable of developing logic for a program and in turn will have the capacity to write
complex programs.
We need to think how we can solve the problem and we need to find out a solution that will solve the
problem.
Once the solutions are obtained we need to find out the ways or the methods to obtain the solution. We need
to find out the logic which defines how to solve the problem
Programming logic is the primary requirements for any programmers to write efficient and effective computer
programs. Program logic is very important in writing the program and it serves as the blue print for any
program.
Every program will definitely start with program logic and end with the coding of programming language
statements.
It tells everything that is required to perform any task. Program logic is used by programmers to model the
programming language instructions that will be executed. Logical model of a program is a blue print for the
instructions that will be converted into programming language statements.
Programming Language Statements: program logic is just a model and it cannot be directly executed and so
we need Programming language statements. Programming language statements are used to implement
program logic by sending instructions to the operating system. Programming language statements is can be
thought of as logic developed for a particular program language.
Note: Logic models are programming language independent and so the logic can be used in any
programming languages.
1.8 Algorithm
Introduction
“An algorithm is a defined as a finite sequence of step-by step instructions that performs a specific task”
Note: An algorithm usually does not solve a task, but is a sequence of steps that, if executed correctly, will give
solution to a task.
An algorithm is a set of instructions that, accepts an input, produces the result and then terminates.
There may more than one algorithm for a specific task, but each will
Have different set of instructions
Takes different amount of time to execute
Require different amount of memory space.
Step 1: Start
Step 2: Take the toothbrush & tooth paste from the brush stand
Step 3: Apply toothpaste over the toothbrush.
Step 4: Brush the tooth
Step 5: Rinse your mouth
Step 6: Place the toothbrush & tooth paste in the brush stand
Step 7: End.
Step 1: Start
Step 2: Take a cup of milk
Step 3: Pour the milk into a vessel.
Step 4: Keep the vessel on the stove.
Step 5: Turn on the stove.
Step 6: Allow it boil.
Step 7: Add required coffee powder and sugar.
Step 8: Turn off the stove after boiling.
Step 9: Pour the content of the vessel into the cup.
Step 10: Stop.
As it is said earlier different algorithms may perform task, but we have to choose the best algorithm. The
characteristics of a good algorithm are as follows.
It should do the given task accurately without any errors.
It should require minimum computer memory.
The time taken to perform the given task should be as minimum as possible.
1.8.4 Examples
“The flow chart can be defined as the pictorial representation of the algorithm”
The flowchart is a means of visually presenting the flow of data. The steps are represented in the form of
different shapes and flow lines are used to interconnect each step.
Usually an architect will have a blue print before starting construction of a building. Similarly, a programmer
will like to have a flowchart before writing a computer program.
The flowchart is drawn according to some defined rules and standard flowchart symbols prescribed by the
American National Standard Institute, Inc.
1.9.1 Introduction
(f) Only one flow line should be used with terminal symbol.
(g) Using the annotation symbol describe the data or computational steps more clearly, if needed.
(h) If the flowchart becomes complex, use connector symbols to reduce the number of flow lines.
(i) Avoid the intersection of flow lines.
(j) Ensure that the flowchart has a logical start and finish.
(k) The validity of the flowchart should be tested by passing through it a sample test data.
1. Complex logic: if the program is lengthy and the logic is complicated, then drawing the flowchart becomes
complex.
2. Alterations and Modifications: If any alterations or modifications are to be done, then the entire flowchart
should be re-drawn completely.
3. Difficult to draw: The flowchart symbols are quite difficult to draw and it consumes more time.
1.9.5 Examples
1.10 Pseudocode
1.10.1 Introduction
Rule 2: proper Indentation should be given to show hierarchy of control structures (i.e. when you are
writing statements within a loop or branch, you should leave a tab space at the beginning of each statement)
Example:
while(condition)
do action1 Proper
do action 2
Indentation
do action 3
END while
Rule 3: End multiline structures properly (i.e every looping or branching control structure should end with a
END keyword )
Example:
while(condition)
do action1
do action 2 End of
do action 3 while Loop
END while
Rule 4: Keep Statements Language Independent (i.e. the keyword that are being used in the pseudo code
should not be specific to any programming language)
1.10.6 Examples
It cannot be easily
Code It cannot be easily converted It can be easily
converted into
Convertibility into code. converted into code.
code.
Psudocode
READ m,n.
INITIALIZE sum to 0
CALCULATE C= m + n
WRITE c
STOP
Example-2
Problem : Average of three Numbers
Algorithm
Step 1: Start
Step 2: Read three numbers, num1, num2 and num3.
Step 3: Add the value of num1, num2 and num3
Step 4: Store the result in sum
Step 5: Find the average as (avg=num/3)
Step 6: Display the average
Step 7: End
Psudocode
READ a, b, c.
CALCULATE avg= (a + b + c )/3
WRITE avg
STOP
Example-3
Problem : Area and circumference of a circle
Algorithm
Step 1: Start
Step 2: Read the value of radius.
Step 3: Set the value of pi = 3.14
Step 4: Find the area as (area=pi*radius*radius)
Step 5: Find the circumference as (circum = 2*pi*radius)
Step 6: Display the area and circumference
Step 7: End
Psudocode
READ radius.
ASSIGN pi =3.14
CALCULATE area= pi*radius*radius
CALCULATE circum= 2*pi*radius
WRITE avg
STOP
Example-4
Problem : Area of a triangle
Algorithm
Step 1: Start
Step 2: Read the value of base and height.
Step 3: Find the area as (area= (1/2)*base*height)
Step 4: Display the area
Step 5: End
Psudocode
Read base, height.
Calculate area= 1/2*base*height
Write area
Stop
Example-5
Problem : Swapping using temporary variable
Algorithm
Step 1: Start
Step 2: Read the values of a and b.
Step 3: Assign the value of a to temp
Step 4: Assign the value of b to a
Step 5: Assign the value of temp to b
Step 6: Display the swapped values of a and b
Step 7: End
Psudocode
READ a, b
temp = a
a=b
b = temp
WRITE a, b
STOP
Example-6
Problem : Swapping without using temporary variable
Algorithm
Step 1: Start
Step 2: Read the values of a and b.
Step 3: Assign the value of a + b to a
Step 4: Assign the value of a - b to b
Step 5: Assign the value of a – b to a
Step 6: Display the swapped values of a and b
Step 7: End
Psudocode
READ a, b
a= a + b
b =a - b
b=a+b
WRITE a, b
STOP
Example-7
Problem : Find the square and cube of a number
Algorithm
Step 1: Start
Step 2: Read a number num1.
Step 3: Find the square of number as (square = pow(num,2))
Step 4: Find the cube of number as (cube= pow(num,3))
Step 5: Display the values of square and cube
Step 6: End
Psudocode
READ num
CALCULATE square = pow(num,2)
CALCULATE cube = pow(num,3)
WRITE square, cube
STOP
Example-8
Problem : Find Positive/Negative
Algorithm
Step 1: start
Step 2: read a number num.
Step 3: IF num is GREATER THAN OR EQUAL to 0 THEN
Display “the number is POSITIVE”.
ELSE
Display “the number is NEGATIVE”.
Step 4: End
Psudocode
READ num
IF (num >= 0) THEN
PRINT “positive”
ELSE
PRINT “positive”
END IF
STOP
Example-9
Problem : Biggest among two numbers
Algorithm
Step 1: Start
Step 2: Read two numbers num1, num2.
Step 3: IF num 1 is GREATER THAN num2
Display “the num1 is GREATER”.
ELSE IF num is EQUAL to 0 THEN
Display “the num1 is Equal to num2”.
ELSE num1 is LESSER THAN num2
Display “the num2 is GREATER”.
Step 4: End
Psudocode
READ num1, num2
IF (num 1 > num2) THEN
PRINT “num1 is greater”
ELSE
IF (num1 < num2) THEN
PRINT “num2 is greater”
ELSE
PRINT “num 1 is equal to num2”
END IF
END IF
STOP
Example-10
Problem : Find Odd/Even
Algorithm
Step 1: Start
Step 2: Read a number num.
Step 3: Find the value of remainder as (remainder=num%2)
Step 4: IF remainder is EQUAL to 0 THEN
Display “the number is EVEN”.
ELSE
Display “the number is ODD”.
Step 5: End
Psudocode
READ num
IF (num%2 == 0) THEN
PRINT “num is odd”
ELSE
PRINT “num is even”
END IF
STOP
Example-11
Problem : A simple Calculator
Algorithm
Step 1: Start
Step 2: Read two numbers num1 and num2.
Step 3: Read a character op (+, -, *, /)
Step 4: IF OP is EQUAL to ‘+’ THEN
BEGIN:
Result = num1 + num2.
Display the result
END
ELSE IF OP is EQUAL to ‘-’ THEN
BEGIN:
Result = num1 - num2.
Display the result
END:
ELSE IF OP is EQUAL to ‘*’ THEN
BEGIN:
Result = num1 * num2.
Display the result
END:
ELSE IF OP is EQUAL to ‘/’ THEN
BEGIN:
Result = num1 / num2.
Display the result
END:
Step 5: End
Psudocode
READ num1, num2
READ operator
CASE operator
CASE ‘+’:
Result = num1 + num2.
PRINT Result
CASE ‘-’:
Result = num1 - num2.
PRINT Result
CASE ‘*’:
Result = num1 * num2.
PRINT Result
CASE ‘/’:
Result = num1 / num2.
PRINT Result
END CASE
STOP
Example-12
Problem : Smallest among three numbers
Algorithm
Step 1: Start
Step 2: Read three numbers num1, num2 and num3.
Step 3: IF num1 is LESS THAN num2
BEGIN:
IF num1 is LESS THAN num3
Display “num1 is smallest”
ELSE IF num2 is LESS THAN num3
Display “num2 is smallest”
ELSE
Display “num3 is smallest”
END:
Step 4: End
Psudocode
READ a, b, c
IF (a < b) THEN
IF (a < c) THEN
PRINT “a is smallest”
END IF
ELSE
IF (b < C) THEN
PRINT “b is smallest”
ELSE
PRINT “c is smallest”
END IF
END IF
STOP
Example-13
Problem : Printing 1 to N
Algorithm
Step 1: Start
Step 2: Read the value of N.
Step 3: Initialize count to 0
Step 4: IF count is GREATER than N then go to step 5
BEGIN:
Display the Value of count.
Increment the value of count
END:
Step 5: End
Psudocode
READ N
INITIALIZE count =1
WHILE (count <= N)
Count =count +1
PRINT count
END WHILE
STOP
Example-14
Problem : Sum of N numbers
Algorithm
Step 1: Start
Step 2: Read the value of N.
Step 3: Initialize count and sum to 0
Step 4: IF count is GREATER than N then go to step 5
BEGIN:
Calculate sum as (sum = sum + count).
Increment the value of count
END:
Step 5: Display the sum
Step 6: End
Psudocode
READ N
INITIALIZE count =1
INITIALIZE sum =0
WHILE (count <=N)
Count =count +1
sum = sum + count
END WHILE
WRITE sum
STOP
Example-15
Problem : Generating Fibonacci Series
Algorithm
Step 1: Start
Step 2: Read the value of N.
Step 3: Initialize f1=0, f2 =1 and Count =2
Step 4: Display f1, f2
Step 5: IF count is GREATER than N then go to step 6
BEGIN:
Calculate f3 as (f3= f1+ f2)
Assign the value of f2 to f1
Assign the value of f3 to f2
Increment the value of count
Display f3
END:
Step 6: End
Psudocode
READ N
INITIALIZE f1 = 0, f2 = 1
PRINT f1, f2
INITIALIZE sum = 0
INITIALIZE count =2
WHILE (count <N)
CALCULATE f3 = f1 + f2
PRINT f3
f1 = f2
f2 = f3
Count =count +1
END WHILE
STOP
Example-16
Problem : Factorial of a given number
Algorithm
Step 1: Start
Step 2: Read the value of N.
Step 3: Initialize fact =1 and Count =0
Step 4: IF count is GREATER than N then go to step 5
BEGIN:
Calculate fact as (fact= fact* count)
Increment the value of count
END
Step 5: Display the value of fact
Step 6: End
Psudocode
READ N
INITIALIZE fact = 1
INITIALIZE count = 0
WHILE (count <N)
CALCULATE fact = fact * count
Count =count +1
END WHILE
WRITE fact
STOP
Example-17
Problem : Sum of Digits
Algorithm
Step 1: Start
Step 2: Read a Number num.
Step 3: Initialize sum=0
Step 4: IF num is NOT GREATER THAN 0 then go to step 5
BEGIN:
Calculate remainder as (remainder= num%10)
Calculate sum as (sum= sum + remainder)
Calculate num as (num= num/10)
END
Step 5: Display the value of sum
Step 6: End
Psudocode
READ num
INITIALIZE sum = 0
WHILE (num > 0)
CALCULATE rem= num % 10
CALCULATE sum= sum + rem
num= num/10
END WHILE
WRITE sum
STOP
Example-18
Problem : Find reverse of a number
Algorithm
Step 1: start
Step 2: read a Number num.
Step 3: initialize rev=0
Step 4: IF num is NOT GREATER THAN 0 then go to step 5
BEGIN:
Calculate remainder as (remainder= num%10)
Calculate rev as (rev= rev*10 + remainder)
Calculate num as (num= num/10)
END
Step 5: display the value of sum
Step 6: End
Psudocode
READ num
INITIALIZE rev = 0
WHILE (num > 0)
CALCULATE remainder= num%10
CALCULATE rev= rev*10 + remainder
CALCULATE num= num/10
END WHILE
WRITE rev
STOP
Example-19
Problem : Generating the series(1 + x + x2 + ……… + xn)
Algorithm
Step 1: Start
Step 2: Read the value of x and n.
Step 3: Initialize sum=0 and count =0.
Step 4: IF count is EQUAL to n then go to step 5
BEGIN:
Calculate sum as (sum= sum + pow(x,count))
END
Step 5: Display the value of sum
Step 6: End
Psudocode
READ X, N
INITIALIZE sum = 0
INITIALIZE count= 0
WHILE (count <= N)
CALCULATE sum = sum + pow(x, ount)
END WHILE
WRITE sum
STOP
Example-20
Problem : String Palindrome
Algorithm
Step 1: Start
Step 2: Read a string
Step3: Reverse the string using strrev function
Step 3: Compare the string and the reversed using strcmp function.
Step 4: IF string and reversed string are equal
Display “palindrome”
ELSE
Display “ not palindrome”
Step 5: End
Psudocode
READ string
String1 = strrev(string)
Compare = strcmp(string,string1)
IF (compare == 0)
PRINT “palindrome”
ELSE
PRINT “not palindrome”
STOP
A computer system consists of both hardware and software. Information stored on computer hardware
is often called software.
The hardware components of a computer system are the electronic and mechanical parts.
The software components of a computer system are the data and the computer programs.
Processor (CPU)
Input devices
Output devices
For typical desktop computers, the processor, main memory,
secondary memory, power supply, and supporting hardware are System Unit
housed in a metal case called System Unit.
Processor (CPU)
Storage device
Secondary (Floppy, CD, DVD, Pen Drive, Hard disk) – Non Voltatile Memory
PRIMARY MEMEORY
Main Memory is a form of Immediate Access Storage also known as primary storage, it is volatile
memory.
Very closely connected to the processor.
Holds the programs and data that the processor is actively working with.
SECONDARY MEMORY
Floppy
CD / DVD Drive
Nearly all computers today come equipped with a CD or DVD drive, usually located on the front of
the system unit.
CD drives use lasers to read (retrieve) data from a CD, and many CD drives can also write (record)
data onto CDs.
Alternatively referred to as a hard disk drive and abbreviated as HD or HDD, the hard drive is the
computer's main storage media device that permanently stores all data on the computer.
A hard drive is a mass storage device found in all PCs (with some exclusions) that is used to store
permanent data such as the operating system, programs and user
files.
INPUT DEVICES
Input and output devices allow the computer system to interact with the outside world by moving data
into and out of the system.
o Keyboard
o Mouse
o Scanner
o Web Camera
o Microphone
o Light Pen
o Joystick
Keyboard
Its structure is like typewriter. It contains no. of keys which have some specific ASCII values. Like
‘A’ has ASCII value 65.
When this is pressed , it is converted into 65 & this 65 is sent to CPU in the form of Binary language
(i.e. 1000001). Then operations are done on this data.
Mouse
A mouse is a small device used to point to and select items on your computer screen.
Mouse Pointer
Advantages
o Easy to use
Primary Button is used to left click and secondary button used to right click
Pointing and clicking with your mouse is the main way to interact with your computer.
Scanner
A scanner is an input device that scans documents such as photographs and pages of text. When a
document is scanned, it is converted into a digital format.
Most scanners are flatbed devices, which mean they have a flat scanning surface.
Another type of scanner is a sheet-fed scanner, which can only accept paper documents.
Web Camera
Microphone
Microphone is an input device to input sound that is then stored in digital form.
Light Pen
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.
Joystick
The lower spherical ball moves in a socket.TheJoystic can be moved in all four directions.
Touch Screen
Since touch screen devices accept input directly through the screen, they do not require external input
devices, such as mice and keyboards
OUTPUT DEVICES
The devices which are used to display the data to the user either in the form of hard copy or soft copy
are called output devices.
o Monitor
o Printer
o Speaker
o Projector
o Plotter
Monitor
The visual display of the LCD Monitor (Left); CRT Monitor (Right)
processed data, which the users can view is got through the monitor.
Computer monitors come in a variety of screen sizes and not to forget visual resolutions.
The next of the computer output devices is the printer, which is an external hardware device, which
takes processed data from the computer to generate a hard copy of the data.
Inkjet Printer (Left); Laser Printer (Right)
There are two types of printers
o Impact Printers
o Non-Impact Printers
Speaker
A speaker is a hardware device that is connected to a computer's sound card, which outputs the sound
generated by the card.
Projector
It is a hardware device, with which an image like a computer screen is projected onto a flat screen.
Image data is sent to the video card, by the computer which is then
translated into a video image and sent to the projector.
Plotter
Plotters, like printers, create a hard copy rendition of a digitally rendered design.
The design is sent to a plotter through a graphics card and the image is created using a pen.
In simple words, plotters basically draw an image using a series of straight lines.
Note: Modems, Network Cards and Touch Screen can act as both input device and output device.
Volatile Memory: The data is lost on reboot. This is the ram 3
memory. Random-access-memory.
Non-Volatile Memory: The data is saved to a hard drive or flash
drive, or it could be a hard coded chip. This is ROM memory.
Read-only-memory.
Business
The characteristics of a computer such as high speed of calculation, diligence, accuracy, reliability, or
versatility has made it a vital part in all business organizations.
Payroll Calculations
Budgeting
Sales Analysis
Financial forecasting
Banking
Banks on-line accounting facility, which includes maintaining account balances, deposits, withdraw,
interest charges, shares and trustee records.
ATM machines are making it even easier for customers to do transaction with banks.
Insurance
Insurance companies are keeping all records up to date with the help of a computer. 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 the information such as
maturity date
interests due
survival benefits
bonus
Education
The uses of computer provide a tool in the Education system is known as CBE (Computer Based
Education).
The computer education is very familiar and rapidly increasing the graph of computer students.
There are number of methods in which educational institutions can use computer to educate the
students effectively.
It is used for preparing a database about student performance and analysis are carried out based on the
performance.
Marketing
Advertising: With computers, advertising professionals create art and graphics, print and disseminate
ads with the goal of selling more products.
At Home Shopping: At home shopping has been made possible through use of computerized
catalogues that provide access to product information and permit purchase of products from home.
Health Care
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
computerized machines.
Diagnostic System: Computers are used to collect data and identify cause of illness.
Lab-diagnostic System: All tests can be done and reports can be 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 side
effects etc.
Engineering Design
One of major areas is CAD (Computer aided design).CAD provides creation, edition, and modification of
designs and image. Some fields are:
Structural Engineering: Requires stress and strain analysis required for design of Ships, Buildings,
bridges, Airplanes etc.
Military
Computers are largely used in defense. Modern tanks, missiles, weapons etc. are computerized control
systems.
Missile Control
Military Communication
Smart Weapons
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.
Chatting
Usenet
FTP
Telnet
Video-conferencing
Government Applications
Budgets
Statistical data
Weather Forecasting.