Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Unit-I GE6151- COMPUTER PROGRAMMING

UNIT I - INTRODUCTION
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.

1.1 INTRODUCTION:
Computer - word derived from Computare – Means to compute or to calculate.
1.1.1 DEFINITION:
It is an electronic machine, devised for performing calculations and controlling
operations that can be expressed either in logical or numerical terms.
It is a fast electronic device which automatically accepts and stores input data, process
them and produce results under the directions of a detailed step by step program.
output
Computer
input
system
process
1.1.2 BASIC FIVE OPERATIONS OF A COMPUTER:
1. Input
 Process of capturing the information
 By using input components can do any process
2. Process - Transformation process to convert from input to output.
3. Output - Result which is the outcome of transformation process.
4. Storing - Process of saving or retaining the data for future use
5. Controlling - Process of directing the sequence in which all operations to be performed.
1.1.3 KEYWORDS:
Data - Fact about anything - raw material of information.
Information - Processed data.
Computer is made up of 2 components. They are
 Hardware
 Software
Hardware - physical equipment. (Ex) All devices

S.KAVITHA / AP / CSE / MSAJCE Page 1 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Software - set of instructions that direct the hardware how to perform task fro any
operation.
(Ex) Car - Hardware
How to drive - Instructions - Software.

1.2 CHARACTERISTICS OF COMPUTER :


Speed:
Computer process data at extremely fast rate.(i.e) Million of instructions per sec. It
perform huge task within some seconds that a human being take hours or years to
complete it.
1 milli second=1*10-3 sec
1 micro second= 1*10-6 sec
1 nana second= 1*10-9 sec
1 Pico second =1*10-12sec
Accuracy:
Level of accuracy depends on instructions and type of machine being used. Errors may
occur in computer. However it may be due to user’s less concentration rather than
technological weakness.(Ex) Errors occur due to imprecise thinking of programmer or
incorrect input data. Error due to incorrect input data or unreliable programs called as
Garbage-in-Garbage-out.
Diligence (or) Endurance:
Unlike human beings, computer is free from monotony, tiredness, lack of concentration.
It works continuously for hours, weeks without error or grumbling.(Ex) Perform 1
million calculations- 1 millionth calculation will be performed correctly as 1st calculation
without any error.
Reliability:
Measurement of performance of computer which is measured against some
predetermined standard of operations without any failure.(Ex.) Hardware Level - does not
require any human intervention between processing operations.
Storage Capability:
Unlike humans, computer can store large amount of data and can recall the regarding
information -maintain and recall after many years too.

S.KAVITHA / AP / CSE / MSAJCE Page 2 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

It mainly has 2 memories


Primary memory - Small in size (RAM)
Secondary memory – Large in size (HD,CD)
Data is fetched from storage memory and processed in memory and again saved in memory.
user can delete data then memory forget it.
Versatility:
Versatile in nature- computer can do almost any job if it is reduced to a series of logical
steps. EX. Many Applications can be exected simultaneously.
Resource Sharing:
In initial stage computers are isolated, but due to the advancement in computer
technology they are connected with each other so that they can share device.
(Ex) Printer in Lab.
Can also share data among group of computers
Automatic:
They are automatic - once started on a job- it continues its work (follows instructions
according to program) until the job is finished. (i.e.) constant supervision is not required.
Example: Missile, Rocket launching-(explanation)
No Intelligent Quotient
Though it performs faster, accurate than humans, it can't think of it own. It duly performs
according to its instructions.

1.3 EVOLUTION OF COMPUTERS:


Computer was invented because of man search for fast and accurate calculating device. In
beginning, counting was done either by using fingers or pebbles. Then Abacus was invented.
Abacus(1000 BC)
Used to do calculations using a system of sliding beads arranged on rack. It was very easy to
handle. So it was used through world wide today.
Other Computing Devices:
Napier Bone and Slide rule were invented.

S.KAVITHA / AP / CSE / MSAJCE Page 3 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Pascaline (1642) -After many years, Blaise Pascal invented the 1st mechanical adding machine
(i.e) automatic calculator called pascaline.It is a brass rectangular box that have 8 movable dials
to add sums eight figures long.
Stepped Reckoner:(1694)
German Mathematician, Gottfried extends the pascal design to perform multiplication, division
and to find square root called as stepped reckoner (1st calculator for multiplication- Performs by
repeated addition.
Disadvantage:
 Not reliable because of lacking of mechanical precision in construction.
Difference and analytical Engine(1822 and 1842)
 Real development of computer was done by English mathematician, Charles
Babbage(Father of Computer).
 Proposed a machine - To perform differential equation called difference Engine which
produce reliable tables.
 In 1842, idea about Analytical engine which is completely automatic It performs basic
arithmetic operation (Average speed of 60 additions/sec)
 Basic design includes input device in the form of cords containing operating instructions
and a store for memory of 1000 numbers up to 50 decimal digits.
 It has control unit which process instructions in any sequence. Output device to produce
printed results. (It was not constructed but gives basic elements of modern computer).
Punched cards:(1889)
Herman Hollerith - use cards to store data, which fed into machine that compile results
mechanically.
Mark I computer (1937-44):
Automatic sequence controlled calculator - 1st fully automatic calculating machine by Howard in
collaboration with IBM.
 Based on Punched card machine technique. It is a electro mechanical device (i.e) both
electrical and mechanical
 Reliable but complex in design and huge in size, slow
 used over 3000 electrically actuated switches to control its operations
 perform 5 arithmetic operations: +,-,*,/,table reference.

S.KAVITHA / AP / CSE / MSAJCE Page 4 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Atanasoff - Berry Computer: (ABC)(1939-42)


 Electronic machine that solves certain mathematical equation
 Developed by Atanasoff Berry
 Used 45 Vaccum tubes for internal logic and capacitors for storage.
ENIAC:(Electronic Numerical Integrator and Calculator) (1936-46)
 Designed by John Eckert and John Mauchly
 Used 18000 vaccum tubes, occupy 20*40 square feet
 Performs addition and multiplication at 200 and 2000 microsec resp.
 used in military to solve ballistic problem mainly in flight and missile
 I st electronic computer
EDVAC(1946-52) Electronic Discrete Variable Automatic Computer:
 Developed by Eckert and Mauchly
 I st electronic computer which use stored program concept that was developed by John
Van Newmann
 Stored Program is a sequence of instructions. Data can be stored in memory of computer
for automatically directing flow of operations.
EDSAC(1947-49) Electronic Delay Storage Auomatic Calculator.
 Developed by Maurice Wilkes.
 Based on John Von Neumann stored program concept
 Perform adddition and mutilplication at 1500 and 4000 microseconds resp.
 Used mercury delay lines for memeory and vaccum tube for logic.
UNIVAC (1951) Universal Automatic Computer
 I st Digital Computer
 used at census Bureau, IBM
LARC machine (1960)
 Access Time < 1microsecs
 Capacity - 1 trillion words
1970
 IC - Made Computer Small, cheap.
 It lead to Microprocessor.

S.KAVITHA / AP / CSE / MSAJCE Page 5 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

1980
 VLSI - 1000 of transistor on single chip
 ROM Used.
Late 1980
 PC with Microprocessor handling 32 bits of data at a time
 4,000,000 instructions/sec
1990
 PC become part of life.

1.4 GENERATIONS OF COMPUTERS:


In computer technology, Generation is described as stage of technological development. The
developments are because of
 The way the computers operate
 Resulting in increasing smaller, cheaper, more powerful, efficient, speed,
memory capacity ,reliability
 According to technology, generations are classified into 5 periods
FIRST GENERATION (1940-1956):
 Uses vacuum tube for circuiting and magnetic drums for memory
 Magnetic drum - metal cylinder coated with magnetic iron oxide material on which data
and programs are stored.
 Input: Punched cards and paper tape
 Output: Printout
 Solve only one problem at a time.
 Use binary coded language for operations-each machine use different binary codes. so it
is difficult for programming which results in lack of versatility and speed.
 To run on different computers, instructions must be rewritten and recompiled.
(Ex) ENIAC - Electronic Numerical Integrator and Calculator
EDVAC- Electronic Discrete Variable Automatic Computer
UNIAC-Universal Automatic Computer
Characteristics:
 Based on vacuum tubes technology

S.KAVITHA / AP / CSE / MSAJCE Page 6 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Computation time is calculated in millisecs


 Large in size-Require lot of space- so they are non-portable.
 Uses vacuum tubes-, which generate large amount of heat. So air conditioning is
necessary.
 Expensive and require large amount of electricity.
 Versatility and speed- slow
 Unreliable- so prone to frequent hardware failure-continuous maintenance is required
 Fastest Computinf device on that time.
 Each individual component has to be assembled manually.
 Production and labour cost is high.
SECOND GENERATION (1956-63):
 Uses transistors - semiconductor material like Germanium and Silicon. It has 3 leads that
perform electrical functions like voltage, current or power amplification with low power
requirement
 Size - small, faster, cheaper, energy-efficient, more reliable than predecessors
 Input- punched card and output - printout
 Magnetic core - Primary Memory
 Magnetic Disk - Secondary Memory
 Use assembly language instead of machine language-assembly language use
mnemonics(abbreviations) for instructions rather than number. So this is less complex
compare to machine language.
o (Ex) ADD for + and MULT for *
 High level language came into existence
o (Ex) FORTRAN, COBOL
 Computation time- Calculated in micro seconds.
 Needs air conditioning.
 Manual assembly of individual component is required.
 (Ex) PDP-8, IBM 140, IBM 7090
THIRD GENERATION (1964-EARLY 1970):
 Use IC - single chip (silicon) with many components such as transistors and resistors
fabricated on it

S.KAVITHA / AP / CSE / MSAJCE Page 7 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 IC replaces several Individual wired transistors. So size - small, reliable and efficient.
 Use keyboard, monitors instead of punched cards and monitor.
 Computation time- Calculated in nano seconds
 Production and maintenance cost is low
 Portable,reliable.
 Manual assembly of individual component is not required
 Since OS used, the device can run many different applications at one time.
o (Ex) NCR 395 and B6500
4G(EARLY 1970'S - TILL DATE):
 Use Microprocessor - circuit contains millions of transistors.
 Built on single piece of silicon called chip, which is about 0.5cm along one side and not
more than 0.05cm thick.
 It lead to LSI era
o LSI- 1000 of transistors in small silicon material.
o VLSI - hundreds of thousands of transistors in single chip.
o Ultra VLSI - millions. so they become smaller, cheaper than before.
 Magnetic memories are replaced by semiconductor memories. So random access
becomes more faster. Moreover semiconductor memories become economical and
smaller.
 Hardware failure is negligible.
 Additional significant - Computers linked together to form networks which leads to the
development of Internet.
 Development of GUI, mouse, and handheld devices takes place.
(Ex) Apple II, CRAY 1, Altair 8800.
FIFTH GENERATION (PRESENT & BEYOND) – AI:
 Dream of creating human like computer that capable of reasoning and reaching a decision
through series of what-if-then analysis. Such computers learn from its mistakes.
 Process of developing 5th generation computer is still in development stage. However
expert system already in use.
 Expert system - computer information system that attempts to mimic thought process and
reasoning of experts in specific areas.

S.KAVITHA / AP / CSE / MSAJCE Page 8 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Characteristics:
 Mega chips:
5G computers use super LSI chip that contain microprocessor-having millions of electronic
components on a single chip.Mega chip approximately enable the computer memory capacity
to human mind.
 Parallel Processing:
Most computers today access and execute only one instruction at a time - serial processing
Parallel processing - accesses several instructions at once and works on them at same time
through use of multiple central processing unit.
 Artificial Intelligence:
series of related technologies that tries to simulate and reproduce human behavior, including
thinking, speaking and reasoning.AI comprise group of components of related technologies.
They are
1. Expert System
2. Natural Language Processing
3. Speech Recognition
4. Vision Recognition and Robotics.

1.5 CLASSIFICATION OF COMPUTER:


We know that, computers are available in many size and types.
Ex: Former systems occupy entire room. Now holds within palm
According to physical size, performance, application areas, system is classified as
a. Micro computer
1. Desktop
2. Laptop
3. Handheld
b. Mini computer
c. Mainframe computer
d. Super computer

S.KAVITHA / AP / CSE / MSAJCE Page 9 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

a) Micro Computer:
 Small, low cost digital computer
 Consist of microprocessor, storage unit, input and output channel-all may be in
one chip inserted into one or several pc boards.
 Addition of power supply, connecting cables, peripherals (keyboard, printer,
monitor, etc), an os and other software program –provide complete
microcomputer system.
 Developed for individual user between networked together and can serve more
than one user.
Ex: IBM pc, Pentium 100, IBM pc Pentium 200, Apple Macintosh.
1. Desktop computer (personal computer):
 Standalone for individual use
 Consist of input, output, etc
 Pros: not very expensive for individuals or small business.
 Pc manufacturer are: Apple, IBM, DELL, Hewlett Packard (hp)
2. Laptop (note book):
 Portable computer-user can carry it.
 Enclose all basic features of desktop
 Pros: can use at anywhere, anytime,-mainly during travel.
 No external power supply needed. It has rechargeable battery which is self
contained in it.
 Expensive when compare to desktop
3. Handheld Computer (palmtop):
 Can conveniently store in pocket
 Smaller than laptop and larger than calculator.
 Use pen or electronic stylus instead of keyboard as input.
 No disk drive-So use Memory cards to store programs and data. However can
connect with printer or disk drive to generate output or store data.
 Has limited memory and less powerful than desktop.
Ex: Apple Newton, Casio cassiopiea, Franklin eBook man

S.KAVITHA / AP / CSE / MSAJCE Page 10 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

b) Minicomputer:
 Developed by digital equipment corporation.
 Small digital computer whose process, storage capacity, speed of processing data is
lesser than that of mainframe but greater than microcomputer.
 Used as desktop device often connected to mainframe to perform auxiliary operation.
 Mainly designed to meet computing needs for several people simultaneously in a
small to medium size business environment – capable of supporting 200 users
simultaneously.
 Serve as centralized storehouse for cluster of workstation or as network server.
 Is a multi user system- so used in interactive application in industries, research
organization, college, university, real time controls and engineering design works.
Ex: PDP11, IBM (8000 series) and VAX 7500
c) Mainframe computer:
 Ultra high performance computer made for high volume, processor intensive
computing
 Consist of high-end computer processor, peripheral devices.
 Capable of performing online transactions processing system, extensive data storage,
retrieval and supporting large volumes of data processing.
 Process, speed, storage –
 Greater than mini
 More greater than micro.
 Second largest in computer family (first – super computer)
 Execute many programs simultaneously at a high speed where as super computer
designed for single process.
 Allows users to maintain large information storage at centralized location and able to
access and process the data from different computer located at different location.
 Used in large business and scientific work.
Ex-IBM’S ES000, VAX 8000, CDC 6600.
d) Super computer:
 Special purpose machine designed for single process (i.e.) to maximize the number of
FLOPS (floating point operation per second)

S.KAVITHA / AP / CSE / MSAJCE Page 11 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Computer less than giga flop per second –not considered as super computer.
 Contains no. Of CPU that operate in parallel to make it faster speed range-400-10000
MFLOPS (Million FLOPS)
 Fastest, costliest, powerful computer among all.
 Solves complex mathematical equation in few hours, which have taken a scientist
with paper for years.
 Used to solve multivariate mathematical problem of existent physical process such as
aerodynamics, metrology and plasma physics.
 Used in
o Military –to simulate defense scenario.
o Cinema- to produce sophisticated animation.
o Scientist-to build complex models.
o Entertainment (advertising industry)
 Cons: More expensive.
Ex: CRAY -3, CYBEP 205 and PARAM.

1.6 ORGANIZATION OF COMPUTER

S.KAVITHA / AP / CSE / MSAJCE Page 12 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

1.INPUT DEVICES
 Anything that feeds the data into the computer. This data can be inalpha-numeric form
which needs to be keyed-in orinits very basic natural form i.e.
hear,smell,touch,see;taste&thesixth sense…feel?
Typicalinputdevicesare:
 Keyboard
 Mouse
 Joy Stick
 Light pen
 Track Ball
 Scanner
 Graphic Tablet
 Microphone
 Magnetic Ink Card Reader(MICR)
 Optical Character Reader(OCR)
 Bar Code Reader
 Optical Mark Reader(OMR)

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

Sr.No Keys Description

1 Typing Keys These keys include the letter keys (A-Z) and digit keys
(0-9) which generally give same layout as that of
typewriters.

S.KAVITHA / AP / CSE / MSAJCE Page 13 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

2 Numeric Keypad It is used to enter numeric data or cursor movement.


Generally, it consists of a set of 17 keys that are laid
out in the same configuration used by most adding
machines and calculators.

3 Function Keys The twelve function keys are present on the keyboard
which are arranged in a row at the top of the keyboard.
Each function key has unique meaning and is used for
some specific purpose.

4 Control keys These keys provide cursor and screen control. It


includes four directional arrow keys. Control keys also
include Home, End, Insert, Delete, Page Up, Page
Down, Control(Ctrl), Alternate(Alt), Escape(Esc).

5 Special Purpose Keys Keyboard also contains some special purpose keys
such as Enter, Shift, Caps Lock, Num Lock, Space bar,
Tab, and Print Screen.

MOUSE
 Mouse is most popular pointing device. It is a very famous cursor-control device having a
small palm size box with a round ball at its base which senses the movement of mouse and
sends corresponding signals to CPU when the mouse buttons are pressed.
 Generally it has two buttons called left and right button and a wheel is present between the
buttons. Mouse can be used to control the position of cursor on screen, but it cannot be used
to enter text into the computer.
Advantages
 Easy to use
 Not very expensive
 Moves the cursor faster than the arrow keys of keyboard.

S.KAVITHA / AP / CSE / MSAJCE Page 14 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

JOYSTICK
 Joystick is also a pointing device which is used to move cursor position on a monitor screen.
It is a stick having a spherical ball at its both lower and upper ends. The lower spherical ball
moves in a socket. The joystick can be moved in all four directions.
 The function of joystick is similar to that of a mouse. It is mainly used in Computer Aided
Designing(CAD) and playing computer games.

Light Pen
 Light pen is a pointing device which is similar to a pen. It is used to select a displayed menu
item or draw pictures on the monitor screen.
 It consists of a photocell and an optical system placed in a small tube. When the tip of a light
pen 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.

Track Ball
 Track ball is an input device that is mostly used in notebook or laptop computer, instead of a
mouse. This is a ball which is half inserted and by moving fingers on ball, pointer can be
moved.

S.KAVITHA / AP / CSE / MSAJCE Page 15 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Since the whole device is not moved, a track ball requires less space than a mouse. A track
ball comes in various shapes like a ball, a button and a square.

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

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

S.KAVITHA / AP / CSE / MSAJCE Page 16 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Microphone
 Microphone is an input device to input sound that is then stored in digital form. The
microphone is used for various applications like adding sound to a multimedia presentation
or for mixing music.

Magnetic Ink Card Reader(MICR)


 MICR input device is generally used in banks because of a large number of cheques to be
processed every day.
 The bank's code number and cheque number are printed on the cheques with a special type
of ink that contains particles of magnetic material that are machine readable.
 This reading process is called Magnetic Ink Character Recognition (MICR). The main
advantages of MICR is that it is fast and less error prone.

S.KAVITHA / AP / CSE / MSAJCE Page 17 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Optical Character Reader(OCR)


 OCR is an input device used to read a printed text.
 OCR scans text optically character by character, converts them into a machine readable code
and stores the text on the system memory.

Bar Code Readers


 Bar Code Reader is a device used for reading bar coded data. Bar coded data is generally
used in labelling goods, numbering the books etc.
 It may be a hand held scanner or may be embedded in a stationary scanner. Bar Code Reader
scans a bar code image, converts it into an alphanumeric value which is then fed to the
computer to which bar code reader is connected.

Optical Mark Reader(OMR)


 OMR is a special type of optical scanner used to recognize the type of mark made by pen or
pencil. It is used where one out of a few alternatives is to be selected and marked.
 It is specially used for checking the answer sheets of examinations having multiple choice
questions.

S.KAVITHA / AP / CSE / MSAJCE Page 18 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

2. OUTPUTDEVICES

 Output devices display information in awaythat you can understand. The most common
output device is a monitor.It looks a lot alike a TV and houses the computer screen.
 The monitor allows you tosee what you and the computer are doing together Output
devices are pieces of equipment that are used to get information or any other response
out from computer.
 These devices display information thathasbeenheldorgeneratedwithina
computer.Outputdevicesdisplay informationinaway that you canunderstand.Themost
commonoutputdeviceisamonitor.
TypesofOutputDevice
Printing: Plotter,Printer
Sound:Speakers
Visual:Monitor
PRINTERS
Printer is an output device, which is used to print information on paper.
There are two types of printers:
 Impact Printers
 Non-Impact Printers
Impact Printers
The impact printers print the characters by striking them on the ribbon which is then pressed on
the paper.
Example:
 Dot Matrix Printer(DMP)
 Daisy Wheel
Characteristics of Impact Printers are the following:
 Very low consumable costs
 Very noisy
 Useful for bulk printing due to low cost
 There is physical contact with the paper to produce an image

S.KAVITHA / AP / CSE / MSAJCE Page 19 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Non-impact Printers
Non-impact printers print the characters without using ribbon. These printers print a complete
page at a time so they are also called as Page Printers.
These printers are of two types
 Laser Printers
 Inkjet Printers
Characteristics of Non-impact Printers
 Faster than impact printers.
 They are not noisy.
 High quality.
 Support many fonts and different character size.

SPEAKERS
Speakersareoutputdevicesthatallow youtohearsoundfromyourcomputer.Computer
speakersarejustlikestereospeakers.Thereareusuallytwoofthemandtheycomeinvarious sizes
MONITORS
Monitors, commonly called as Visual Display Unit (VDU), are the main output device of a
computer. It forms images from tiny dots, called pixels that are arranged in a rectangular form.
The sharpness of the image depends upon the number of pixels.
There are two kinds of viewing screen used for monitors.
 Cathode-Ray Tube (CRT)
 Flat- Panel Display

3. MEMORYOR PRIMARYSTORAGE
Purpose of Storage
 Thefundamentalcomponents ofageneral-purposecomputerare arithmetic and logicunit,
controlcircuitry,storagespace, andinput/outputdevices.
 Ifstoragewasremoved,thedevice we hadwouldbea
simplecalculatorinsteadofacomputer.Theabilitytostoreinstructionsthat
formacomputerprogram, andtheinformationthattheinstructionsmanipulateiswhatmakes
storedprogramarchitecturecomputersversatile.

S.KAVITHA / AP / CSE / MSAJCE Page 20 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Primarystorage,orinternalmemory,iscomputer
memorythatisaccessibletothecentralProcessingunitofacomputerwithouttheuseofcomputer'sinput/
outputchannelsPrimarystorage,alsoknownasmainstorageormemory,isthemainareainacomputerin
whichdataisstoredforquickaccessbythecomputer'sprocessor.

PrimaryStorage
 Primarystorageisdirectlyconnectedtothecentralprocessingunitofthecomputer.
 Itmustbe presentforthe
CPUtofunctioncorrectly,justasinabiologicalanalogythelungsmustbe
present(foroxygenstorage) forthehearttofunction.
 As showninthediagram,primarystoragetypicallyconsistsofthreekindsofstorage:

Mainmemory
 It containstheprogramsthatarecurrentlybeingrunandthedatatheprogramsareoperatingon.
 The
arithmeticandlogicunitcanveryquicklytransferinformationbetweenaprocessorregisterandlocat
ions in mainstorage, also knownasa "memoryaddresses".
 In moderncomputers, electronicsolid-
staterandomaccessmemoryisusedformainstorage,andisdirectlyconnectedtotheCPUviaa"mem
orybus"anda"databus".

Cache memory
 It is a special type of internal memory used by many central processing units to increase
their performanceor"throughput".
 Someoftheinformationinthemainmemoryisduplicatedin thecache memory,whichisslightly
slowerbutofmuchgreatercapacity thantheprocessorregisters,andfasterbut much smaller
thanmain memory.

Random Access Memory (RAM)

S.KAVITHA / AP / CSE / MSAJCE Page 21 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 RAM(Random Access Memory) is the internal memory of the CPU for storing data,
program and program result. It is read/write memory which stores data until the machine is
working. As soon as the machine is switched off, data is erased.
 Access time in RAM is independent of the address that is, each storage location inside the
memory is as easy to reach as other locations and takes the same amount of time. Data in the
RAM can be accessed randomly but it is very expensive.
 RAM is volatile, i.e. data stored in it is lost when we switch off the computer or if there is a
power failure. Hence a backup uninterruptible power system(UPS) is often used with
computers. RAM is small, both in terms of its physical size and in the amount of data it can
hold.
RAM is of two types
 Static RAM (SRAM)
 Dynamic RAM (DRAM)

STATIC RAM (SRAM)


 The word static indicates that the memory retains its contents as long as power is being
supplied. However, data is lost when the power gets down due to volatile nature.
 SRAM chips use a matrix of 6-transistors and no capacitors. Transistors do not require
power to prevent leakage, so SRAM need not have to be refreshed on a regular basis.
 Because of the extra space in the matrix, SRAM uses more chips than DRAM for the same
amount of storage space, thus making the manufacturing costs higher. So SRAM is used as
cache memory and has very fast access.
Characteristic of the Static RAM
 It has long life

S.KAVITHA / AP / CSE / MSAJCE Page 22 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 There is no need to refresh


 Faster
 Used as cache memory
 Large size
 Expensive
 High power consumption
DYNAMIC RAM (DRAM)
DRAM, unlike SRAM, must be continually refreshed in order to maintain the data. This is
done by placing the memory on a refresh circuit that rewrites the data several hundred times per
second. DRAM is used for most system memory because it is cheap and small. All DRAMs are
made up of memory cells which are composed of one capacitor and one transistor.
Characteristics of the Dynamic RAM
 It has short data lifetime
 Need to be refreshed continuously
 Slower as compared to SRAM
 Used as RAM
 Lesser in size
 Less expensive
 Less power consumption
ROM(READ ONLY MEMORY)
 ROM stands for Read Only Memory. The memory from which we can only read but cannot
write on it.
 This type of memory is non-volatile. The information is stored permanently in such
memories during manufacture.
 A ROM, stores such instructions that are required to start a computer. This operation is
referred to as bootstrap.
 ROM chips are not only used in the computer but also in other electronic items like washing
machine and microwave oven.

S.KAVITHA / AP / CSE / MSAJCE Page 23 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Following are the various types of ROM


MROM (Masked ROM)
 The very first ROMs were hard-wired devices that contained a pre-programmed set of data
or instructions. These kind of ROMs are known as masked ROMs which are inexpensive.
PROM (Programmable Read only Memory)
 PROM is read-only memory that can be modified only once by a user. The user buys a blank
PROM and enters the desired contents using a PROM program.
 Inside the PROM chip there are small fuses which are burnt open during programming. It
can be programmed only once and is not erasable.
EPROM(Erasable and Programmable Read Only Memory)
 The EPROM can be erased by exposing it to ultra-violet light for a duration of up to 40
minutes. Usually, an EPROM eraser achieves this function.
 During programming, an electrical charge is trapped in an insulated gate region. The charge
is retained for more than ten years because the charge has no leakage path.
 For erasing this charge, ultra-violet light is passed through a quartz crystal window(lid). This
exposure to ultra-violet light dissipates the charge. During normal use the quartz lid is sealed
with a sticker.
EEPROM(Electrically Erasable and Programmable Read Only Memory)
 The EEPROM is programmed and erased electrically. It can be erased and reprogrammed
about ten thousand times. Both erasing and programming take about 4 to 10 ms (milli
second).
 In EEPROM, any location can be selectively erased and programmed. EEPROMs can be
erased one byte at a time, rather than erasing the entire chip.
 Hence, the process of re-programming is flexible but slow.
Advantages of ROM

S.KAVITHA / AP / CSE / MSAJCE Page 24 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Non-volatile in nature
 These cannot be accidentally changed
 Cheaper than RAMs
 Easy to test
 More reliable than RAMs
 These are static and do not require refreshing

4. SECONDARY STORAGE DEVICES


The purpose of storage in a computer is to hold data or information and get that data to the CPU
as quickly as possible when it is needed. Computers use disks for storage: hard disks that are
located inside the computer, and floppy or compact disks that are used externally.
• Computers Method of storing data & information for long term basis i.e. even after PC
is switched off.
• It is non – volatile
• Can be easily removed and moved & attached to some other device
• Memory capacity can be extended to a greater extent
• Cheaper than primary memory

Hard Disks
 Inside the hard disk drive case you will find circular disks that are made from polished steel.
On the disks, there are many tracks or cylinders.
 Within the hard drive, an electronic reading/writing device called the head passes back and
forth over the cylinders, reading information from the disk or writing information to it.
 Hard drives spin at 3600 or more rpm (Revolutions Per Minute) - that means that in one
minute, the hard drive spins around over 7200 times!
Optical Storage

S.KAVITHA / AP / CSE / MSAJCE Page 25 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

• Compact Disk Read-Only Memory (CD-ROM)


• CD-Recordable (CD-R)/CD-Rewritable (CD-RW)
• Digital Video Disk Read-Only Memory (DVD-ROM)
• DVD Recordable (DVD-R/DVD Rewritable (DVD-RW)
• Photo CD

5. CPU(CENTRAL PROCESSING UNIT)


 Referred to as ‘brain’ of computer –converts data (input) to meaningful information
(output).
 Highly complex, extensive set of electronic circuitry which executes stored program
instruction.
 Controls all internal and external devices, performs arithmetic and logical programs
operation, and operates only on binary data.
 Controls usage of main memory to store data and instruction and controls the sequence of
operation.

A. ALU:
 Contains electronic circuitry – executes all arithmetic and logical operation on data made
available to it-has 2 units.
 Arithmetic unit - responsible for performing actual computing and carry out arithmetic
calculations at a very high speed.
 Logic unit - perform logical operations based on instruction provided on it.
 Operation - logical comparison between data item.

S.KAVITHA / AP / CSE / MSAJCE Page 26 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Can compare no’s, letters or special character and can then take action
based on compared result.
 Logical operation- check equal to condition, greater than condition, less
than condition

B. Control unit
This unit controls the operations of all parts of computer but does not carry out any
actual data processing operations.
Functions of this unit are:
 It is responsible for controlling the transfer of data and instructions among other units of
a computer.
 It manages and coordinates all the units of the computer.
 It obtains the instructions from the memory, interprets them, and directs the operation of
the computer.
 It communicates with Input/Output devices for transfer of data or results from storage.
 It does not process or store data.

CONTROL UNIT
C. Memory Unit (registers):
 Registers are special purpose; high speed temporary memory unit holds various types
of information like data, instruction, address and intermediate results of calculation.
 It holds information that CPU is currently working on.

S.KAVITHA / AP / CSE / MSAJCE Page 27 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

1.7 NUMBER SYSTEM:


When we type some letters or words, the computer translates them in numbers as computers can
understand only numbers.
A computer can understand positional number system where there are only a few symbols called
digits and these symbols represent different values depending on the position they occupy in the
number.
A value of each digit in a number can be determined using:
 The digit
 The position of the digit in the number
 The base of the number system (where base is defined as the total number of digits
available in the number system).
As a computer programmer or an IT professional, you should understand the following number
systems, which are frequently used in computers.
S.N. Number System & Description
Decimal Number System
1. Base 10
Digits used:0,1,2,3,4,5,6,7,8,9
Binary Number System
2. Base 2
Digits used: 0, 1
Octal Number System
3. Base 8
Digits used: 0 to 7
Hexa Decimal Number System
4.
Base 16.

S.KAVITHA / AP / CSE / MSAJCE Page 28 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Digits used: 0 to 9, Letters used: A- F

Decimal Number System


 The number system that we use in our day-to-day life is the decimal number system. Decimal
number system has base 10 as it uses 10 digits from 0 to 9.
 In decimal number system, the successive positions to the left of the decimal point represent
units, tens, hundreds, thousands and so on.
 Each position represents a specific power of the base (10). For example, the decimal number
1234 consists of the digit 4 in the units position, 3 in the tens position, 2 in the hundreds
position, and 1 in the thousands position, and its value can be written as
(1x1000)+ (2x100)+ (3x10)+ (4xl)
(1x103)+ (2x102)+ (3x101)+ (4xl00)
1000 + 200 + 30 + 4
1234
Binary Number System
Characteristics
 Uses two digits, 0 and 1.
 Also called base 2 number system.
 Each position in a binary number represents a 0 power of the base (2). Example, 20.
 Last position in a binary number represents a x power of the base (2). Example, 2x where
x represents the last position - 1.
Example
Binary Number: 101012
Octal Number System
Characteristics
 Uses eight digits: 0, 1, 2, 3, 4, 5, 6, 7.
 Also called base 8 number system.
 Each position in a octal number represents a 0 power of the base (8). Example, 80.

S.KAVITHA / AP / CSE / MSAJCE Page 29 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Last position in a octal number represents a x power of the base (8). Example, 8x where x
represents the last position - 1.
Example
Octal Number: 125708

Hexadecimal Number System


Characteristics
 Uses 10 digits and 6 letters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
 Letters represent numbers starting from 10. A = 10. B = 11, C = 12, D = 13, E = 14, F =
15.
 Also called base16 number system.
 Each position in a hexadecimal number represents a 0 power of the base (16). Example,
160.
 Last position in a hexadecimal number represents a x power of the base (16). Example,
16x where x represents the last position - 1.
Example
Hexadecimal Number: 19FDE16
CONVERSIONS
1.Decimal Number to Binary Conversion
Conversion of 2510 to Binary

2510 Binary equivalent=110012`


Conversion of 25.125 to Binary
Step1: Processing Integer part: 25

S.KAVITHA / AP / CSE / MSAJCE Page 30 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

2510=110012

Step2: Processing Decimal part


0.125 X 2 = 0.250
0.250 X 2 = 0.5
0.5 X 2 = 1.0
25.12510 = 11001.0012
2.Binary Number to Decimal Conversion
Conversion of 1 0 1 0 1 Decimal
Step Binary Number Decimal Number
Step 1 101012 ((1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20))10
Step 2 101012 (16 + 0 + 4 + 0 + 1)10
Step 3 101012 (21)10
Conversion of 1 1001.001to Decimal

3.Decimal to Octal Conversion

S.KAVITHA / AP / CSE / MSAJCE Page 31 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

1.Conversion of 12510 to Octal

12510=1758
2. Conversion of 84.25010 to Oct
Converting the decimal part as

Converting the fraction part


0.250 X 8 = 2.000
25.12310 = 124.28
4.Octal to decimal Conversion
1. Conversion of 125708to Decimal
Step Octal Number Decimal Number
Step 1 125708 ((1 x 84) + (2 x 83) + (5 x 82) + (7 x 81) + (0 x 80))10
Step 2 125708 (4096 + 1024 + 320 + 56 + 0)10
Step 3 125708 (5496)10

Note: 125708 is normally written as 12570.


2. Conversion of Octal 1 2 4 . 2to Decimal

S.KAVITHA / AP / CSE / MSAJCE Page 32 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

124.28=25.25010
5.Decimal to Hexadecimal conversion
Conversion of 45010 to Hexadecimal

45010=1C216
6.Hexadecimal to Decimal conversion
Conversion of19FDE16 to Decimal
Step Binary Number Decimal Number
Step 1 19FDE16 ((1 x 164) + (9 x 163) + (F x 162) + (D x 161) + (E x 160))10
Step 2 19FDE16 ((1 x 164) + (9 x 163) + (15 x 162) + (13 x 161) + (14 x 160))10
Step 3 19FDE16 (65536+ 36864 + 3840 + 208 + 14)10
Step 4 19FDE16 10646210
Note: 19FDE16 is normally written as 19FDE.

7. Binay to octal Conversion


 OCTAL – BASE 8 = 23
 Split in to 3 Digit Binary Number
 Add preceding zeros to the remaining positions

Example 1 :110012 OCTAL


11001
011001

S.KAVITHA / AP / CSE / MSAJCE Page 33 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

3 1
110012=318
Example 2 : 11100112 OCTAL
1110011
001 110011
1 6 3
11100112=1638

8. Binary to Hexa Decimal Conversion


 HEXA – BASE 16 = 24
 Split into 4 DIGIT BINARY NUMBER
 Add preceding zeros to the remaining positions
Example:110012 HEXA
1 1001
0001 1001
1 9
110012=1916
9. Octal To Hexadecimal
 Represent octal number into binary format
 Combine 4 bits from LSB on words.
 Write the equivalent Hexadecimal number
Example:318 HEXA
3 1
011001
00011001
1 9
318=1916
10. Hexadecimal to Octal
 Represent Hexadecimal number into binary format
 Combine 3 bits from LSB on words.

S.KAVITHA / AP / CSE / MSAJCE Page 34 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 Write the equivalent Octal number


Example: 1BD  OCTAL
1 B D
000110111101
000 110111101
0 6 7 5
1BD = 6758

1.8 PLANNING THE COMPUTER PROGRAM


Computer works on a set of instructions called as computer programs.
 Developing a program:
To develop a program the programmer must determine
1. The instructions.
2. The order in which those instructions are to be performed.
3. The data required.
Example:
Adding two numbers;

A, B C=A+B C

A and B are input.


Addition is process.
C is output.
1.8.1 PROGRAM DEVELOPMENT CYCLE:
Analyze /define the problem:
The problem is analyzed completely. Based on that the developer knows the scope of the
problem.
Task analysis:
Developing various solutions to the given problem. From these solutions optimum solution is
chosen.
Designing phase:

S.KAVITHA / AP / CSE / MSAJCE Page 35 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

After selecting the appropriate solution the algorithm is developed. Algorithms may be
represented as flowcharts.This algorithm will depict the logic.
Testing the algorithm for accuracy:
The Purpose of testing
1) To identify the logical errors because the logical errors are more difficult
to correct at the later stages.
2) To check whether the algorithm is true one.
3) To check whether the algorithm works for the normal data and the unusual
data.
Coding:
Programming languages are used to do coding.
Test and debug the program:
A compiler and the programmer designed test data machine test the code to find the syntax
errors. The results obtained can be compared with the manually calculated results. Depending on
the complexity several rounds of testing may be required.
Program development cycle
Analyze problem Documentation
&Implementation

Task analysis Test and


Debugprogram
Designing phase Coding

Algorithm testing

Documentation and implementation:


It is the duty of the programmer to ensure that the documentation is prepared properly for the
programs.

1.8.2 PURPOSE OF PLANNING THE PROGRAM:


 A programmer cannot write instructions to be followed by a computer, unless the
programmer knows how to solve the problem manually.

S.KAVITHA / AP / CSE / MSAJCE Page 36 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

 If you know steps to be followed for solving the problem, but while solving the
problem you forget to apply some of the steps, or you apply the calculation steps in
the wrong sequence, you will get the wrong answer.
 Similarly while writing the computer program, if the programmer leaves out some of
the instructions for the computer or writes the instructions in a wrong sequence the
computer will calculate the wrong answer.
 Hence to produce the effective computer program it is necessary that the programmer
writes every instruction in the proper sequence.
 However the logic of the program may be complex.
 Hence in order to ensure that the program instructions are appropriate for the
problem, and are in the correct sequence, programs must be planned, before they are
written.
1.8.3 ALGORITHMS
DEFINITION:
A finite sequence of instructions thet,when provided with the set of inputs produces an output
and then terminates.Algorithm can have steps to repeat or require decisions until the task is
completed.For the same task different algorithms(different time,space,efforts) are
possible.Performing an algorithm does not guarantee a solution.
Example:
Algorithm to find the largest among three numbers.
Step 1: Start
Step 2: read three numbers say A,B,C
Step 3: Find the larger number between Anad B and store it in MAX_AB
Step 4: Find the larger between MAX_AB and C and store it in MAX_AB.
Step 5: Display MAX
Step 6: Stop
KEY FEATURES OF AN ALGORITHM
1) Algorithm Properties or characteristics:
2. There must be no ambiguity in any instruction.
3. There should not be any uncertainity about which instruction is to be executed
next.

S.KAVITHA / AP / CSE / MSAJCE Page 37 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

4. The algorithm should conclude after a finite number of steps.


5. The algorithm must be general enough to deal with any contigency.
2) Qualities of Good algorithm:
1. Time: To execute the program the computer system takes some amount of time.
The lesser is the time required, the better is the algorithm.
2. Memory: To execute the program the computer takes some amount of memory
storage. The lesser is the memory required the better is the algorithm.
3. Accuracy: Multiple algorithms may provide suitable or correct solutions to a
given problem, some of these may provide accurate results than others, such
algorithms must be suitable.
4. Sequence: The procedure of an algorithm must form in a sequence and some of
the instructions of an algorithm may be repeated in number of times or until a
particular condition is met.
5. Generability: The designed algorithm must solve a single isolated problem and
more often algorithm are designed to handle a range of input data to meet this
criteria, so the algorithms must be generalised.
DIFFERENT WAYS OF STATING ALGORITHMS:
1) Normal English
2) Flowchart
3) Pseudocode
4) Decision Table
5) Program
Normal English:
The algorithm can be easily represented in step-by-step sequential order in normal English, such
algorithms are easy to understand, write and read.
Flowchart
A flowchart is a diagrammatic representation that illustrates the sequence of operations to be
performed to get the solution of a problem.
Pseudocode
It provides a high level description of an algorithm but suppresses many of the details that are
insignificant.

S.KAVITHA / AP / CSE / MSAJCE Page 38 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Decision Table
It helps a lot in designing a specific segment of a design. It provides another way to look at a
complex, nested selection to help clarify the conditions to be tested and how those conditions
should be nested to arrive at the proper actions.
Program:
The algorithm can be represented as a program using any high level language, which becomes a
program.
Flowcharts – Standards for flowcharts, Guidelines for drawing flowcharts.
1.8.4 FLOWCHART
 The flowchart is a means of visually presenting the flow of data through an information
processing systems, the operations performed within the system and the sequence in which
they are performed.
 The program flowchart can be likened to the blueprint of a building. As we know a designer
draws a blueprint before starting construction on a building. Similarly, a programmer prefers
to draw a flowchart prior to writing a computer program.
 As in the case of the drawing of a blueprint, the flowchart is drawn according to defined rules
and using standard flowchart symbols prescribed by the American National Standard
Institute, Inc.

MEANING OF A FLOWCHART

 A flowchart is a diagrammatic representation that illustrates the sequence of operations to be


performed to get the solution of a problem.
 Flowcharts are generally drawn in the early stages of formulating computer solutions.
 Flowcharts facilitate communication between programmers and business people.
 These flowcharts play a vital role in the programming of a problem and are quite helpful in
understanding the logic of complicated and lengthy problems.
 Once the flowchart is drawn, it becomes easy to write the program in any high level
language.
 Often we see how flowcharts are helpful in explaining the program to others. Hence, it is
correct to say that a flowchart is a must for the better documentation of a complex program.

S.KAVITHA / AP / CSE / MSAJCE Page 39 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

GUIDELINES FOR DRAWING A FLOWCHART


 Flowcharts are usually drawn using some standard symbols; however, some special symbols
can also be developed when required.
 Some standard symbols, which are frequently, required for flowcharting many computer
programs are shown above,

The following are some guidelines in flowcharting:


1. In drawing a proper flowchart, all necessary requirements should be listed out in logical
order.
2 The flowchart should be clear, neat and easy to follow. There should not be any room for
ambiguity in understanding the flowchart.
3 The usual direction of the flow of a procedure or system is from left to right or top to
bottom.
4 Only one flow line should come out from a process symbol.

S.KAVITHA / AP / CSE / MSAJCE Page 40 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

or
5. Only one flow line should enter a decision symbol, but two or three flow lines, one for each
possible answer, should leave the decision symbol.

6. Only one flow line is used in conjunction with terminal symbol.

7. Write within standard symbols briefly. As necessary, you can use the annotation symbol to
describe data or computational steps more clearly.

8. If the flowchart becomes complex, it is better to use connector symbols to reduce the number
of flow lines. Avoid the intersection of flow lines if you want to make it more effective and
better way of communication.
9. Ensure that the flowchart has a logical start and finish.
It is useful to test the validity of the flowchart by passing through it with a simple test data.
Advantages and Limitations of using flowcharts, Pseudocode
ADVANTAGES OF USING FLOWCHARTS
The benefits of flowcharts are as follows:
1. Communication: Flowcharts are better way of communicating the logic of a system to all
concerned.
2. Effective analysis: With the help of flowchart, problem can be analyzed in more effective
way.

S.KAVITHA / AP / CSE / MSAJCE Page 41 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

3. Proper documentation: Program flowcharts serve as a good program documentation,


which is needed for various purposes.
4. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis
and program development phase.
5. Proper Debugging: The flowchart helps in debugging process.
6. Efficient Program Maintenance: The maintenance of operating program becomes easy
with the help of flowchart. It helps the programmer to put efforts more efficiently on that
part
LIMITATIONS OF USING FLOWCHARTS
1. Complex logic: Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy.
2. Alterations and Modifications: If alterations are required the flowchart may require re-
drawing completely.
3. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem.
4. The essentials of what is done can easily be lost in the technical details of how it is done.
Sample exercises for algorithmsand flowcharts
SAMPLE ALGORITHMS:
1.To round off an integer to the next largest multiple of another integer.
Step 1 :Input the value of the integer to round off and store in integer variable i. Input the
other integer to whose multiple has to be rounded off to and store in integer variable j.

Step 2: Round off the value of i to the next largest multiple of j and store the value in integer
variable k using the formula
k= i+j – i(mod)j

Step 3: Print the value of variable k onto the screen.

Step 4:Stop.

2.To find the largest among two numbers.

S.KAVITHA / AP / CSE / MSAJCE Page 42 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Step 1: Start
Step 2: Read three numbers say A,B
Step 3: Find the larger number between Anad B and store it in MAX
Step 4: Display MAX
Step 5: Stop.

FEW EXAMPLES ON FLOWCHART


Example 1
Draw a flowchart to find the sum of first 50 natural numbers.

Example 2
Draw a flowchart to find the largest of three numbers A,B, and C.

S.KAVITHA / AP / CSE / MSAJCE Page 43 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

Example 3
Draw a flowchart for computing factorial N (N!) Where N! = 1 ´ 2 ´ 3 ´ …… N .

1.8.5 PSEUDOCODE
Meaning of pseudocode:
a) Pseudo: Imitation .
b) Code :Instructions.
Pseudocode uses English statements rather than symbols to represent the processes.
Program design language :It is nothing but the other name given to the pseudocode.
Goal: To provide a high level description of an algorithm but suppresses many of the details that
are insignificant.
Example: Pseudocode to calculate the area of the rectangle.
PROMPT the user to enter the height and width of the rectangle.
COMPUTE the area by multiplying the height with width.
DISPLAY the area.

S.KAVITHA / AP / CSE / MSAJCE Page 44 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

STOP.

5) Keywords:
Input:READ,OBTAIN,GET ,PROMPT.
Output:PRINT,DISPLAY,SHOW
Compute:COMPUTE ,CALCULATE,DETERMINE
Initialise:SET,INITIALISE.
Add One:INCREMENT
Logic Structures in pseudocode:
The steps are normally "sequence," "selection, " "iteration," and a case-type statement. The
"selection" is the "if then else" statement, and the iteration is satisfied by a number of statements,
such as the "while," " do," and the "for," while the case-type statement is satisfied by the
"switch" statement.
Sequence:Information flows in straight line.
First instruction.
Second instruction
Third instruction
…..
…..
Selection:Decisions are made according to the predefined condition
Pseudocode for IF:
IF Condition THEN
Actions
ELSE
Actions
ENDIF.
Pseudocode for SWITCH:
SWITCH choice
CASE 1:
Action

S.KAVITHA / AP / CSE / MSAJCE Page 45 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

CASE 2:
Action
END CASE
Repetition:Where the logic is repeated in a loop.
Pseudocode for Do…While.
REPEAT
Actions
UNTIL condition

Pseudocode for While.


WHILE condition
DO
Action
END WHILE.
Pseudocode Guidelines:
1. Statements should be written in simple english
2. Steps must be understandable.
3. Instructions should be written in separate line.
4. keywords should be capitalized
5. One entry and one exit should be there.
6. Easy transition from design to coding should be possible.
Benefits of pseudocode:
1. It is language independent.So it can be used by all the programmers.
2. It is easier to develop a program from a pseudocode than a flowchart. Because
Syntaxes are not necessary to develop a psuedocode.
3. It can be accomplished by less experienced programmers.
4. The words and phrases are in line with computer operations so it is easy to
convert the pseudocode in to flowchart.
5. pseudocode is compact.
Limitations of pseudocode:
1. No visual representation is provided.

S.KAVITHA / AP / CSE / MSAJCE Page 46 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

2. No accepted standards for writing pseudocode.


3. Pseudocode cannot be compiled nor executed.
Pseudocode- Sample exercises
FEW EXAMPLES ON PSEUDOCODE
Example 1:
To print Passed if the student’s grade is greater than 60 and failed if the students
name less than 60.
1. IF student's grade is greater than or equal to 60 THEN
2. PRINT "passed"
3. else
4. Print "failed"
5. ENDIF

Example 2:
To print the average marks of ten students.
1. SET total to zero
2. DO
3. SET grade counter to one
4. WHILE grade counter is less than or equal to ten
5. INPUT the next grade
6. COMPUTE the Addition of grade and save the result in total
7. SET the class average to the total divided by ten
8. PRINT the class average.
9. ENDWHILE.
Example 3:
To find the average of the grades.
1. INITIALIZE total to zero
2. INITIALIZE counter to zero
3. INPUT the first grade
4. WHILE the user has not as yet entered the sentinel
5. DO

S.KAVITHA / AP / CSE / MSAJCE Page 47 of 48


Unit-I GE6151- COMPUTER PROGRAMMING

6. COMPUTE the addition of this grade and the running total


7. INCREMENT the grade counter by one
8. INPUT the next grade (possibly the sentinel)
9. ENDWHILE
10. IF the counter is not equal to zero THEN
11. SET the average to the total divided by the counter
12. PRINT the average
13. ELSE
14. PRINT 'no grades were entered'
15. ENDIF

PRACTICE QUESTIONS
1. Draw a flowchart and pseudocode to read a number N and print all its divisors.
2. Draw a flowchart and pseudocode for computing the sum of the digits of any given
number
3. Draw a flowchart and pseudocode to find the sum of given N numbers.
4. Draw a flowchart and pseudocode to computer the sum of squares of integers from 1 to
50
5. Draw a flowchart and pseudocode to arrange the given data in an ascending order.
PRACTICE QUESTIONS
1. Draw an algorithm to read a number N and print all its divisors.
2. Draw an algorithm for computing the sum of the digits of any given number
3. Draw an algorithm to find the sum of given N numbers.
4. Draw an algorithm to computer the sum of squares of integers from 1 to 50
5. Draw an algorithm to arrange the given data in an ascending order.

S.KAVITHA / AP / CSE / MSAJCE Page 48 of 48

You might also like