SlideShare a Scribd company logo
1
Unit I
Introduction to computer and computing
1.0 Introduction
1.1 Objective
1.2 Basic structure and functioning
1.3 Types of Memory
1.4 I/O devices
1.4.1 Input devices
1.4.1.1 Keyboard
1.4.1.2 Point and draw devices
1.4.1.3 Data scanning devices
1.4.1.4 Digitizer
1.4.1.5 Electronic card reader
1.4.1.6 Voice recognition device.
1.4.1.7 Vision input system
1.4.1.8 Myc
1.4.2 Output devices
1.4.2.1 Monitor
1.4.2.2 Printer
1.4.2.3 Plotter
1.4.2.4 Computer output microfilm
1.4.2.5 Screen Image Projector
1.4.2.6 Voice response system
1.5 Storage Devices.
1.5.1 Magnetic tape
1.5.2 Hard disk
1.5.3 Floppy disc
1.5.4 Compact disc
1.5.5 Video CD
1.5.6 Zip drive
1.5.7 DVD
1.5.8 DVD-RW
1.6 Operating system
1.7 Computer languages
1.8 Data processing
1.9 Principles of programming
1.9.1Method of problem solving
1.9.2 Algorithm
1.9.3 Flowchart
Check your progress Answer key
2
1.0 Introduction
The basic logical structure of the computer based on the stored program concept, as proposed
by Von Neumann, has not changed over the years; though the size, shape, performance
reliability and cost of computer have all changed. All computer systems perform the
following five basic operations: inputting i.e. the process of entering data and instructions
into the computer system; storing i.e. saving data and instructions so that they are available
for initial or for additional processing as and when required; processing i.e. performing
arithmetic operations (add, subtract, multiply and divide etc.); outputting and controlling. In
this chapter we will discuss about all of the above basic functions of the computer and its
associated topics.
1.1 Objective
The goal of this unit is to familiarize you with the computer system . We will be
studying about the following :
1. The functions performed by computer system.
2. I/O devices.
3. Storage devices and the different types of memory.
4. Operating system concept and its goals.
1.2 Basic structure and functioning of a computer
A computer or a computer system is basically an electronic machine that can carry out
specific tasks by following sequences of instructions within a program. A program includes
such a sequence of instructions together with the data definition. The computer executes the
program by performing one instruction after the other in the specified order.
The programmer or any computer user needs knowledge of the basic computer
architecture concepts to clearly understand the structure of the computer, so as to be able to
use the computer or develop solutions to problems, and to use the computer as a tool to
execute the solutions to his problems.
All computer systems perform the fundamental functions i.e. input, processing, and output.
Input involves entering data into the computer for processing. Data is entered into the
computer with an input device (for example, the keyboard).
Processing executes the instructions in memory to perform some transformation and/or
computation on the data in the computer's memory. This emphasizes the fact that the
instructions and data must be located in memory in order for the processing to proceed.
3
Output involves transferring data from the computer to an output device such as the computer
screen or monitor.
Mainly there are two types of computers. They are digital and analog computer. The basic
differences between the two types are given below:
Analog Digital
1. It processes analog signals 1. It processes numbers
2. Accuracy is limited 2. It has unlimited accuracy
3. Operation is performed by very few devices 3. Operation is performed by many
devices
4. Basic building blocks are amplifiers 4. Basic building blocks are logic
gates
A computer automatically performs arithmetic & logic operation and gives output. It consists
of 5 functional units, which are as follows: -
1. Input
2. Output
3. Memory
4. C.U
5. A.L.U
1. Input: - The computer accepts coded information through input devices. The most
well known input device is the keyboard, which is electronically, connected to the
CPU. Many other kinds of input devices are also available such as joysticks, track ball
and mouse.
2. Memory: - The function of the memory is to store data and program.
3. Output: -The output is the counterpart of the input device. Its function is to send
processed data to the outside world. Such output devices are monitor, printer, plotters
etc.
4. Control unit: - Its function is to control the functions of input and output devices. The
C.U. is effectively the nerve centre that sends control signals to other units and senses
their states. Data transfer between the processor and memory is controlled by the
C.U. through timing signals. A large set of wires carries the signals to all units.
5. Arithmetic and Logic unit (A.L.U): -Most computer operations are executed in the
A.L.U of the processor. Any other operation is initiated by bringing the required
operands into the A.L.U where the necessary operations are performed.
4
Basic operational concepts: - The following block diagram shows flow of signals and data
between the various units of the computer.
Input unit
The input unit links the external environment with the computer. Data and
instructions are entered into the computer through the input device. Input unit transfers input
data into machine language i.e. binary code.
Following functions are performed by an input unit.
1. It accepts the list of instructions and data from the outside world.
2. It converts these instructions and data in computer acceptable form.
3. It supplies the converted instructions and data to the computer system for further
processing.
Output Unit
The output unit links the computer system with the external environment. It gives us
information, which is obtained as a result of data processing as computer work with binary
code. The result produced is also in the binary form. Hence it must be converted in human
readable form and this task is accomplished by the output interface.
Following functions are performed by an output unit:
5
1. It accept the result produced by computer.
2. It converts these coded result to human acceptable(readable) form.
3. It supplies the converted results to the outside world.
Storage unit
The data and instructions that are entered into the computer system through input
units have to be stored inside the computer before the actual processing starts. Similarly, the
result produced by the computer after processing is also kept somewhere inside the computer
system before being passed onto the output unit. The intermediate result produced by the
computer must also be preserved for ongoing processing, the storage unit of computer system
is designed to serve all these needs. It provides space for storing data and instructions space
for intermediate result and also space for the final result. In short the functions of the storage
unit are :
1. It stores (receives) the data to be processed and instructions required for processing.
2. It stores the intermediate result of processing.
3. It also stores the final result of processing before these results are released to an
output device.
The storage unit of all computers comprises of the following two types of storage:
Primary Storage:- The primary storage is also known as the main memory. It stores pieces of
program instructions and data, intermediate results of processing and the recently produced
result of processing of the job on which computer system was working currently. CPU
accesses the result with very fast speed. The primary memory is volatile and its contents
disappear when the computer is powered off.
Secondary storage:- Secondary storage is also known as auxiliary storage. The secondary
storage is used to supplement the limited storage and volatile characteristics of primary
storage. It is cheaper than primary storage, and can retain information even after the computer
system is switched off.
Central Processing Unit
The Control unit and arithmetic and logic unit of the computer system together make the
CPU i.e. Central processing unit. The CPU is the brain of the computer system. CPU is also
responsible for activating and controlling the operations of other units of the computer
system.
Arithmetic logic unit:- Actual execution of the instructions takes place in the arithmetic and
logic unit. The calculations and comparisons and other decision making is performed in the
ALU.
6
Control Unit:- Control unit maintains order and directs the operation of the entire system. The
control unit acts as the central nervous system for the other components of the computer
system.
Check your progress (1)
Fill in the blank:-
1. ..............................., ......................., ...............................,is fundamental function of
computer.
2. ...............................,unit accept data from outside world.
3. ................................,stores data.
4. Arithmatic nd logical operation done in.........................unit.
1.3 Types of Memory
Every computer has storage space known as memory. There are two types of memory
1. Main memory or Primary memory
2. Secondary memory or auxiliary memory.
Primary memory is of the following types:-
1. RAM
2. ROM
3. PROM
4. EPROM
Random access memory (RAM):It is a primary memory which is also of two types i.e. Static
RAM and Dynamic RAM.
Read only memory (ROM): Special type of random access memory called as read only
memory, is non volatile memory. Data stored on ROM is permanent and cannot be altered by
the programmer. ROM is mainly used to store programs and data which do not change and
are frequently used. ROM chip of the computer stores a set of instructions that are needed to
make the computer system ready for use when its power is switched on. There are two types
of ROM i.e. PROM and EPROM.
Programmable read only memory ( PROM): It is a type of ROM on which data can be written
only once . Once the chip has been programmed the recorded information cannot be changed.
PROM is also known as non volatile storage.
Erasable programmable read only memory (EPROM): In this type of ROM it is possible to
erase the information stored in the chip and can be reprogrammed to store new information,
this type of memory is called EPROM. EPROM are of two types i.e. UVPROM and
EEPROM.
1. UVPROM: Information stored in the chip can be erased by exposing the chip for
some time to ultraviolet light.
7
2. EEPROM: The information stored in the chip can be erased by using high electric
voltage.
Secondary Memory has been discussed under section 3.3
Check your progress (2)
Say whether true or false:-
1. Main memory also called primary memory.
2. RAM is random accept memory.
3. Information stored on EEPROM erased by high electric voltage.
1.4 Input Output Device
An I/O device( an input/output device) is a hardware device that provides the means
of communication between the computer and outer world. They are also known as peripheral
devices because they surround the CPU and the memory of the computer system. Input
devices are used to enter the data from outside world to primary storage and output devices
give results from primary storage to users.
1.4.1 Input Device
An input device is a hardware device that sends data to the computer. Without any
input device, a computer would only be a processing device and not allow users to interact
with it. In other words, an input device is an electromechanical device that accepts data from
outside world and translates them into a form the computer can interpret. Input devices are
broadly classified into following categories.
 Keyboard
 Point-and-draw device
 Data scanning device
 Digitizer
 Electronic card-based device
 Voice recognition device
 Vision based device
 Offline data entry device
1.4.1.1 Keyboard
The keyboard is the most commonly used input device today that allows data
entry into a computer by pressing a set of keys. Keyboard can be classified into two
types
 General purpose keyboard
 Special purpose keyboard
8
General purpose keyboard
General purpose keyboard is a standard keyboard that is most commonly used
as an input device. It has the set of typewriter-like keys that enables you to enter data
into a computer. Computer keyboards are similar to electric-typewriter keyboards but
contain additional keys. The keys on computer keyboards are often classified as
follows:
 alphanumeric keys -- letters and numbers
 punctuation keys -- comma, period, semicolon, and so on.
 special keys -- function keys, control keys, arrow keys, Caps Lock key, and so on.
The standard layout of letters, numbers, and punctuation is known as a QWERTY
keyboard because the first six keys on the top row of letters spell QWERTY. The QWERTY
keyboard was designed in the 1800s for mechanical typewriters and was actually designed to
slow typists down to avoid jamming the keys. Another keyboard design, which has letters
positioned for speed typing, is the Dvorak keyboard.
There is no standard computer keyboard, although many manufacturers imitate the
keyboards of PCs. There are actually three different PC keyboards: the original PC keyboard,
with 84 keys; the AT keyboard, also with 84 keys; and the enhanced keyboard, with 101
keys. The three differ somewhat in the placement of function keys, the Control key, the
Return key, and the Shift keys.
In addition to these keys, keyboards contain the following keys: Page Up, Page Down,
Home, End, Insert, Pause, Num Lock, Scroll Lock, Break, Caps Lock, Print Screen.
Special purpose keyboard
This type of keyboard is specially designed and used for specific type of applications,
so it is called a special purpose keyboard. It makes possible data entry at a faster rate and
enables rapid interaction with computer system. It has only some special functional keys. For
example terminals used in supermarket, ATM etc.
1.4.1.2 Point-and-draw device
The GUI provides users a screen full of graphics icons or menus and allows them to
make a rapid selection from displayed icons or menus to give instruction to computer. Such
user interface computer requires an input device that can be used to rapidly point to and select
a particular graphic icon or menu item from the multiple options displayed on the screen.
Mouse, joystick, trackball, light pen, touch screen are some examples of point-and-draw
devices.
9
Mouse
A mouse is a hardware input device that was invented by Douglas Engel Bart in 1963.
The mouse allows an individual to control a pointer in a graphical user interface (GUI).
Utilizing a mouse, a user has the ability to perform various functions such as opening a
program or file and does not require the user to memorize commands, like those used in a
text-based command-line environment such as MS-DOS.
The mouse was originally referred to as an X-Y Position Indicator for a display system.
Xerox later applied the name mouse to its revolutionary Alto computer system in 1973.
Today, a pointing device is found on virtually every computer.
Trackball
A trackball is an input device that looks like an upside-down mouse. The on-screen pointer is
moved by the trackball with a thumb or finger. A trackball requires less arm and wrist motion
than a regular mouse takes and therefore is often less stressful for the user to use.
Joystick
The joystick is an input device that looks similar to a control device you would find on an
arcade game at your local arcades. A joystick allows an individual to easily move an object in
a game such as navigating a plane in a flight simulator
Light pen
A light pen is an input device that utilizes a light-sensitive detector to select objects on a
display screen. A light pen is similar to a mouse, except that with a light pen you can move
the pointer and select objects on the display screen by directly pointing to the objects with the
pen.
Touch screen
A touch screen is a computer display screen that is also an input device. The screens are
sensitive to pressure; a user interacts with the computer by touching pictures or words on the
screen.
1.4.1.3Data scanning devices
Data scanning devices are input devices that enable direct data entry into a computer
system from source documents thus eliminating the need to key-in text data into the
computer. Due to reduced human effort in data entry, they improve data accuracy and also
increase the timeliness of the information processed. They however demand high quality of
input documents. Some data scanning devices are also capable of recognizing marks or
characters.
1. Image Scanner
10
It is an input device that translates paper documents into an electronic format for
storage in a computer. Electronic format of a scanned image is its bitmap representation.
Stored images can be altered or manipulated with image-processing softwares.
Common Types of Image Scanners
 Flat - bed Scanner
 Hand - held Scanner
Flat - bed Scanner
It looks like a photocopy machine. It has a box with a glass plate on the top & a
lid. The document to be scanned is placed on the glass plate. A light source below
the glass plate moves from one line to another & scans all the lines within few
seconds.
Hand – held Scanner
It contains LEDs & can be held in hand. To scan, it is dragged slowly over the
document from one end to another. It has to be dragged very slowly & steadily. It
is used only when high accuracy is not needed. It is cheaper than a flatbed
scanner. It is used when volume of documents to be scanned is low.
Other scanners include: sheetfed scanner, which is a scanner that scans paper fed
into it, and a card scanner, which is a small scanner capable of scanning business
cards.
2. OCR – Optical Character Recognition
 It is a scanner with character recognition software.
 It uses OCR software that converts the bit map images of characters to
ASCII codes.
 It enables word processing of input text and also requires less space for
storing the document.
 OCR software is extremely complex because it is difficult to make a
computer recognize an unlimited number of fonts
 Two standard OCR fonts are OCR-A (American standard) and OCR-B
(European standard)
3. OMR – Optical Mark Reader
11
 It is a scanner capable of recognizing a pre-specified type of mark by a
pencil or pen
 It is very useful for grading tests with objective type questions, or for any
input data that is of a choice or selection nature.
4. Bar Code Reader
 It is a scanner used for reading (decoding) bar-coded data .
 Bar codes represent alphanumeric data by a combination of adjacent
vertical lines (bars) by varying their width and the spacing between
them.
 Scanner uses laser-beam to stroke across pattern of bar code. Different
patterns of bars reflect the beam in different ways sensed by a light-
sensitive detector.
 Universal Product Code (UPC) is the most widely known bar coding
system.
 Barcode Printer is a hardware device capable of printing out adhesive
barcodes that can be attached to a product. This helps identify the
product or a company keep to track of its inventory.
5. MICR – Magnetic Ink Character Recognition
 MICR is used by banking industry for faster processing of large volume of
cheques.
 Bank’s identification code (name, branch, etc.), account number and cheque
number are pre-printed (encoded)using characters from a special character
set on all cheques.
 Special ink is used that contains magnetizable particles of iron oxide
 MICR reader-sorter reads data on cheques and sorts them for distribution to
other banks or for further processing.
1.4.1.4 Digitizer
 It is an input device used for converting (digitizing) pictures, maps and
drawings into digital form for storage in computers.
 Commonly used in the area of Computer Aided Design (CAD) by architects
and engineers to design cars, buildings medical devices, robots, mechanical
parts, etc.
 Used in the area of Geographical Information System(GIS) for digitizing
maps available in paper form.
1.4.1.5 Electronic Card Reader
 Electronic cards are small plastic cards having encoded data appropriate for
the application for which they are used.
 Electronic-card reader is used to read data encoded on an electronic card and
transfer it to the computer for further processing.
 Used together as a means of direct data entry into a computer system.
12
 Used by banks for use in automatic teller machines(ATMs) and by
organizations for controlling access of employees to physically secured areas.
1.4.1.6 Voice Recognition Devices
Input devices that allow a person to input data to a computer system by speaking
to it are called voice recognition devices. Today’s speech recognition systems are
limited to accepting few words within a relatively small domain and can be used
to enter only limited kinds and quantities of data.
Uses of Speech Recognition
 For inputting data to a computer system by a person in situations where
his/her hands are busy.
 For data input by dictation.
 For authentication of a user by a computer system based on voice input.
 For limited use of computers by individuals with physical disabilities.
1.4.1.7 Vision - Input Systems
 Allow computer to accept input just by seeing an object.
 Input data is normally an object’s shape and features in the form of an
image.
Digital camera
A digital camera stores the pictures or video it takes in electronic format
instead of to a film. There are several features that make digital cameras a popular
choice when compared to film cameras. First, the feature often enjoyed the most is
the LCD display on the digital camera. This display allows users to view photos or
video after the picture or video has been taken, which means if you take a picture
and do not like the results, you can delete it; or if you do like the picture, you can
easily show it to other people. Another nice feature with digital cameras is the
ability to take dozens, sometimes hundreds of different pictures. Digital cameras
have become the camera solution for most users today as the quality of picture they
take has greatly improved and as the price has decreased.
1.4.1.8 Myc
Sometimes abbreviated as mic, a microphone is a hardware peripheral originally
invented by Emile Berliner in 1877 that allows computer users to input audio into
their computers.
Check your progress (3)
Fill in the blanks:-
13
1. Flat panel display is ………………….device.
2. Com stands for……………………
3. To print engineering design application………………is used.
4. …………………converts text information into spoken sentence.
1.4.2 Output Devices
An output device is an electrometrical device that accepts data from a computer and
translates it into human understandable form and displays the result. It is also known as a
peripheral device. The output devices are broadly classified into the following categories :
 Monitor
 Printer
 Plotter
 Computer output microfilm
 Screen image projector
 Voice response system
1.4.2.1 Monitor
Monitor is also called a video display terminal (VDT) or video display unit (VDU).
In its most common usage, monitor refers only to devices that contain no electronic
equipment other than what is essentially needed to display and adjust the
characteristics of an image.
Like most TVs, the computer monitor has a CRT (Cathode Ray Tube) that is found
inside the computer monitor. The CRT is the main component and most expensive
part in the computer monitor.
Flat-panel display
Thin screen displays found with all portable computers are becoming the new
standard with desktop computers. Instead of utilizing the cathode-ray tube technology,
flat-panel displays use Liquid-crystal display (LCD) technology or other alternative
making them much lighter and thinner when compared with a traditional monitor
1.4.2.2 Printer
A printer is n external hardware device that is responsible for taking computer data
and generating a hard copy of that data. Printers are one of the most used peripherals
on computers and are commonly used to print text, images, or photos. Printers are of
the following types:
 Dot Matrix printer
 Inkjet printer
 Laser printer
14
 Thermal printer
 LED printer
Dot-matrix printer
It is a type of printer that produces characters and illustrations by striking pins against
an ink ribbon to print closely spaced dots in the appropriate shape. Dot-matrix printers
are relatively expensive and do not produce high-quality output. However, they can
print to multi-page forms (that is, carbon copies), something laser and ink-jet printers
cannot do.
Dot-matrix printers vary in two important characteristics:
speed: Given in characters per second (cps), the speed can vary from about 50 to
over 500 cps. Most dot-matrix printers offer different speeds depending on the quality
of print desired.
print quality: Determined by the number of pins (the mechanisms that print the
dots), it can vary from 9 to 24. The best dot-matrix printers (24 pins) can produce near
letter-quality type, although you can still see a difference if you look closely.
Inkjet printer
The most popular printer for home computer users that prints by spraying streams of
quick-drying ink on paper. The ink is stored in disposable ink cartridges, often a
separate cartridge is used for each of the major colors. These colors are usually Black,
Red/Magenta, Green/Cyan, and Yellow (CYMK).
Although inkjet printers themselves are often relatively inexpensive, the ink
cartridges used in the printers can increase the overall cost of the printer.
Laser printer
First developed at Xerox PARC by Gary Starkweather and released in 1971, a laser
printer is a printer that utilizes laser technology to print images on the paper. Laser
printers are often used in corporate, school, and other environments that require print
jobs to be completed quickly and in large quantities.
Thermal printer
1. A thermal impact printer or electro thermal printer is a printer that uses heated
pins to "burn" images onto heat-sensitive paper. These printers are commonly used in
calculators and fax machines; and although they are inexpensive and print relatively
fast, they produce low resolution print jobs.
2. A thermal printer, thermal transfer printer, or thermal wax-transfer printer is a
high quality printer invented by Jack Kilby that commonly utilizes a thermal wax
ribbon that melts a colored wax onto the paper creating near photo-realistic images.
15
LED Printer
Short for light emitting diode printer, LED printers were developed by Casio and are
printers capable of printing at the same or close to the same quality as most laser
printers. LED printers work much like laser printers but utilize a LED panel that
recreates the image on a negatively charged drum. The areas where the light hits the
drum become less charged, which attracts the toner. The printer then transfers the
toner from the drum to the paper and applies intense heat to fuse the toner to the
paper.
1.4.2.3 Plotters
It is a device that draws pictures on paper based on commands from a computer.
Plotters differ from printers in that they draw lines using a pen. As a result, they can
produce continuous lines, whereas printers can only simulate lines by printing a
closely spaced series of dots. Multicolor plotters use different-colored pens to draw
different colors.
In general, plotters are considerably more expensive than printers. They are used in
engineering applications where precision is mandatory. There are two types of
plotters: drum plotter and flatbed plotter.
1.4.2.4 Computer Output Microfilm
COM (Computer Output Microfilm) is a process for copying data from electronic
media on computers onto microfilm. COM can be produced as microfiche or as
16mm-roll microfilm.
A high-speed recorder transfers machine-readable digital data onto human-readable
microfilm using laser technology and a processor, which develops the microfilm after it is
exposed to the light source. The recorder can operate off-line as a stand-alone device, or
on-line connected to a local or wide-area network. A COM recorder usually has a
duplicator connected to it that can create as many copies as needed. A sorter separates the
duplicate fiche cards into bins.
1.4.2.5 Screen image projector
A digital projector, also called a digital projection display system, is a specialized
computer display that projects an enlarged image on a movie screen. Such devices are
commonly used in presentations.
The term digital projector is sometimes used for a program that facilitates the viewing
of three-dimensional (3D), interactive, full-motion audio-visual files on a personal
computer. Versions are available for both IBM-compatible and Macintosh computers,
and can be downloaded from the Internet. They can be used as plug-ins for popular
browsers for viewing animated Web-page content. For optimum performance on the
16
Internet, a broadband connection should be used because of the high-speed,
interactive nature of the content, and because the transmitted files are often large
There are two main types of digital projection display systems. The older, less
expensive type employs three transparent liquid-crystal-display ( LCD ) panels, one
for each of the primary colors (red, green, and blue). The light transmittivity of each
pixel varies depending on the image data received from the computer. The light from
a lamp is directed through the LCD panels, collimated using a lens, and projected onto
a screen. The overall construction of the device is similar to that of a slide projector,
where the "slide" consists of the three LCD panels placed close together near the focal
point of the projection lens. Advantages of LCD technology include efficiency, ease
of brightness and contrast adjustment, and high image resolution.
A newer, more expensive scheme is known as Digital Light Processing (DLP), a
proprietary technology developed by Texas Instruments. In a DLP display, tiny
mirrors are used instead of transparent panels. Each mirror represents one pixel. The
light, rather than passing through the panel, is reflected from it. The mirrors move
back and forth, varying the amount of light that reaches the projection lens from each
pixel. Color is obtained by passing the light from the lamp through a rotating wheel
with red, green, and blue filters. This subjects the mirrors to light at each of the
primary colors in a rapid rotating sequence. The result is a color-modulated image that
the human eye sees as natural color. Advantages of DLP technology include light
weight, high contrast, and lack of pixelation.
1.4.2.6 Voice response system
A voice recognition system allows user to talk with the computer. It has an audio
response device that produce audio output, audio response device is basically of two
type one is Voice Reproduction System and other is Speech Synthesizer.
Voice Reproduction System
It produces audio output by selecting appropriate audio output from a set of
prerecorded audio responses.
Speech Synthesizer
A speech synthesizer converts text information into spoken sentences. To produce
speech, these devices combine basic sound units called phonemes. From a given text
information, sequence of words are combined into phonemes, amplified, and output
through the speaker attached to the system.
Check your progress (4)
Fill in the blanks:-
1. ………………device is used for converting picture, maps and drawing in digital
form.
2. Data code in form of small lines is known as ……………
17
3. ………………..are capable of recognize a pre specified type of mark made by
pencil or pen.
1.5 Storage devices
A storage device is a hardware device capable of storing information. There are two
storage devices used in computers: a primary storage device such as computer RAM
and a secondary storage device such as a computer hard disk drive.
Secondary storage device
Alternatively referred to as external memory and auxiliary storage, secondary storage
is a storage medium that holds information until it is deleted or overwritten regardless
of the computer being on or off. For example, a floppy disk drive and hard disk drive
are both good examples of secondary storage devices. There are three different types
of storage on a computer. Although primary storage is accessed much faster than
secondary storage because of the price and size limitations, secondary storage is used
with today's computers to store all programs and personal data.
1.5.1 Magnetic tape
Tapes for computers are similar to tapes used to store music. It is a coated strip of
plastic on which data is magnetically encoded
Storing data on tapes is considerably cheaper than storing data on disks. Tapes also
have large storage capacities, ranging from a few hundred kilobytes to several
gigabytes. Accessing data on tapes, however, is much slower than accessing data on
disks. Tapes are sequential-access media, which means that to get to a particular point
on the tape, the tape must go through all the preceding points. In contrast, disks are
random-access media because a disk drive can access any point at random without
passing through intervening points.
Because tapes are so slow, they are generally used only for long-term storage and
backup. Data to be used regularly is almost always kept on a disk. Tapes are also used
for transporting large amounts of data. Tapes come in a variety of sizes and formats.
Tapes are sometimes called streamers or streaming tapes.
1.5.2 Hard Disk
A magnetic disk is a device on which you can store computer data. The term hard is
used to distinguish it from a soft, or floppy, disk. Hard disks hold more data and are
faster than floppy disks. A hard disk, for example, can store anywhere from 10 to
more than 100 gigabytes, whereas most floppies have a maximum storage capacity of
1.4 megabytes.
A single hard disk usually consists of several platters. Each platter requires two
read/write heads, one for each side. All the read/write heads are attached to a single
access arm so that they cannot move independently. Each platter has the same number
of tracks, and a track location that cuts across all platters is called a cylinder. For
18
example, a typical 84 megabyte hard disk for a PC might have two platters (four
sides) and 1,053 cylinders.
In general, hard disks are less portable than floppies, although it is possible to buy
removable hard disks.
1.5.3 Floppy
A floppy is a soft magnetic disk. It is called a floppy because it flops if it is waved..
Unlike most hard disks, floppy disks (often called floppies or diskettes) are portable,
because you can remove them from a disk drive. Disk drives for floppy disks are
called floppy drives. Floppy disks are slower to access than hard disks and have less
storage capacity, but they are much less expensive. And most importantly, they are
portable.
Floppies come in three basic sizes: 8 ½”, 5 ¼” and 3 ½”.
1.5.4 CD-ROM
Pronounced see-dee-rom. Short for Compact Disc-Read-Only Memory, a type of
optical disk capable of storing large amounts of data -- up to 1GB, although the most
common size is 650MB (megabytes). A single CD-ROM has the storage capacity of
700 floppy disks, enough memory to store about 300,000 text pages.
CD-ROMs are stamped by the vendor, and once stamped, they cannot be erased and
filled with new data. To read a CD, you need a CD-ROM player. All CD-ROMs
conform to a standard size and format, so you can load any type of CD-ROM into any
CD-ROM player. In addition, CD-ROM players are capable of playing audio CDs,
which share the same technology.
CD-ROMs are particularly well-suited to information that requires large storage
capacity. This includes large software applications that support color, graphics, sound,
and especially video.
1.5.5 VCD
VCD stands for 'Video Compact Disc' and basically it is a CD that contains moving
pictures and sound. A VCD has the capacity to hold up to 74/80 minutes on
650MB/700MB CDs respectively of full-motion video along with quality stereo
sound. VCDs use a compression standard called MPEG to store the video and audio.
A VCD can be played on almost all standalone DVD Players and of course on all
computers with a DVD-ROM or CD-ROM drive with the help of software based
decoder / player. It is also possible to use menus and chapters, similar to DVDs, on a
VCD and also simple photo album/slide shows with background audio. The quality of
a very good VCD is about the same as a VHS tape based movie but VCD is usually a
bit more blurry.
VCD was introduced in 1993 by JVC, Philips, SONY and Matsushita .Video data is
demanding in terms of storage capacity; it requires approximately 5 MB of storage
19
per second of video, which would translate to about two minutes of video on a 680
MB CD. In order to store video information on a CD in a practical fashion, the data
must be compressed for storage and then decompressed for replay in real time.
1.5.6 Zip drive
A zip drive is a high-capacity floppy disk drive developed by Omega Corporation. Zip
disks are slightly larger than conventional floppy disks, and about twice as thick.
They can hold 100 or 250 MB of data. Because they're relatively inexpensive and
durable, they have become a popular media for backing up hard disks and for
transporting large files.
1.5.7 DVD
DVD stands for Digital Versatile/Video Disc, DVD-R stands for DVD-
Recordable and DVD-RW for DVD-Rewriteable. A recordable DVD stores up to 2
hours of very good quality DVD-Video, including several audio tracks in formats like
stereo, Dolby Digital or DTS and also advanced menu systems, subtitles and still
pictures that can be played by many standalone DVD players and most computer
DVD-ROMs. If you choose to lower the video quality it is possible to store several
hours video on a recordable DVD using low bit rates and low resolution. It is also
possible to have upto 4.37 GB ordinary data or mix DVD-Video and data on a
recordable DVD that can be played by most computer DVD-ROMs.
There are many competing DVD Recording standards, DVD-R / DVD-RW and
DVD+R / DVD+RW have pretty similar features and are compatible with many
standalone DVD Players and most DVD-ROMs while DVD-RAM has less DVD
Player and DVD-ROM compatibility but better recording features.
DVD-R and DVD-RW
DVD-R was the first DVD recording format released that was compatible with
standalone DVD Players.DVD-R is a non-rewriteable format and it is compatible with
about 93% of all DVD Players and most DVD-ROMs. DVD-RW is a rewriteable
format and it is compatible with about 80% of all DVD Players and most DVD-
ROMs. DVD-R and DVD-RW supports single side 4.37 GiB* DVDs(called DVD-5)
and double sided 8.75 GB* DVDs(called DVD-10).These formats are supported by
DVD Forum.
20
DVD+R and DVD+RW
DVD+R is a non-rewritable format and it is compatible with about 89% of all DVD
Players and most DVD-ROMs.DVD+RW is a rewritable format and is compatible
with about 79% of all DVD Players and most DVD-ROMs.DVD+R and DVD+RW
supports single side 4.37 GiB* DVDs(called DVD-5) and double side 8.75 computer
GB* DVDs(called DVD-10).These formats are supported by the DVD+RW Alliance.
DVD+R DL
DVD+R DL or called DVD+R9 is a Dual Layer writeable DVD+R. The dual layered
discs can hold 7.95 GiB* (called DVD-9) and dual layered with double sides 15.9*
GiB (called dvd-18).
DVD-R DL
DVD-R DL or called DVD-R9 is a Dual Layer writeable DVD-R. The dual layered
discs can hold 7.95 GiB* (called DVD-9) and dual layered with double sides 15.9*
GiB (called dvd-18).
DVD-RAM
DVD-RAM has the best recording features but it is not compatible with most DVD-
ROM drives and DVD-Video players. Think more of it as a removable hard disk.
DVD-RAM is usually used in some DVD Recorders.
Check your progress (5)
Say whether true or false:-
1. Magnetic tape is a storage device
2. Harddisk is less portable than floppy
3. Wc can store moving picture in VCD
1.6 Operating System
The operating system forms an integral part of the computer system. It is essential to
have knowledge about it, its components, goals, functions, importance etc. There are
varieties of operating systems prevalent around the world and many new ones keep coming
in. Each new developed operating system may have some new enhanced features and
functionality but the basic features of all operating systems remain the same. With newer
21
version, efforts are made to enhance features of the operating system in order to provide a
less troublesome session to the user. Here we will try to get a good understanding about the
basic functions of the operating system and its importance.
The most basic and simple definition of an operating system is “the software that
controls the hardware.” It is a set of programs that make the computer hardware useable. It
acts as an interface between the user and the hardware. It provides an environment within
which other programs can do useful work.
An operating system is a program designed to run other programs on a
computer. A computer’s operating system is its most important program. It is considered
the backbone of a computer, managing both software and hardware resources. Operating
systems are responsible for everything from the control and allocation of memory to
recognizing input from external devices and transmitting output to computer displays. They
also manage files on computer hard drives and control peripherals, like printers and
scanners.
The operating system of a large computer system has even more work to do.
Such operating systems monitor different programs and users, making sure everything runs
smoothly, without interference, despite the fact that numerous devices and programs are
used simultaneously. An operating system also has a vital role to play in security. Its job
includes preventing unauthorized users from accessing the computer system.
The abstract view of the components of a computer system shows the position of the
operating system as below:
USERS
Operating system is an essential part of every computer system. The users are able
to make efficient use of the basic computing resources available in the system with the help
Application s/w
Utility s/w, system program
Operating system
hardware
22
of the softwares especially the operating system. The operating system acts as an
intermediary between the user of a computer system and the hardware. It controls and
coordinates the use of hardware among the various application programs for the various
users. It provides an environment so that the user can do his work in an efficient manner
and also easily and conveniently
Some examples of operating systems are UNIX, Mach, MS-DOS, MS-Windows,
Windows/NT, Chicago, OS/2, MacOS, VMS, MVS, and VM.
Operating systems are classified on the basis of their mode of interaction with
the users as CUI (character user interface) and GUI (graphic user interface).
 Under CUI, user has to type-in commands in proper syntax, for example DOS operating
system.
 GUI provides a picture oriented interface that provides menus and icons which can be
selected by clicking on the icon with the help of a mouse. The user interacts with the
operating systems through the user interface and is usually interested in the “look and
feel” of the operating system, for example WINDOWS operating system.
The most important components of the user interface are the command interpreter, the
file system, on-line help, and application integration.
Operating systems are also differentiated as being real time, multi-programmed,
multiprocessing, multitasking, multithreading, networked, distributed, client- server,
multiuser, time shared, clustered etc.
 A multiuser operating system enables multiple users to run programs simultaneously.
This type of operating system may be used for just a few people or hundreds of them.
In fact, there are some operating systems that are used to allow thousands of people to
run programs at the same time.
 A multiprocessing operating system allows a program to run on more than one central
processing unit (CPU) at a time. This can come in very handy in some work
environments, at schools, and even for some home-computing situations. Multitasking
operating systems work a little differently; they make it possible to run more than one
program at a time. Multithreading operating systems are even more different, allowing
varied parts of one program to be used simultaneously.
23
 Real-time operating systems are designed to allow computers to process and respond to
input instantly. Usually, general-purpose operating systems, such as disk operating
system (DOS), are not considered real time, as they may require seconds or minutes to
respond to input. Real-time operating systems are typically used when computers must
react to the consistent input of information without delay. For example, real-time
operating systems may be used in navigation, manufacturing units for controlling the
operation of machines.
Operating systems generally have following three major goals:
 To hide details of hardware from the user through abstraction.
 To allocate resources to processes.
 Provide a pleasant and effective user interface
Operating system components: Even though, not all systems have the same
structure, many modern operating systems support the following system components:
process management, primary memory management, file management, i/o system
management, secondary storage management, security management and networking issues.
Operating system functions: Some of the operating system functions are listed as
below:
 implementing the user interface,
 sharing hardware among users,
 allowing users to share data among themselves,
 preventing users from interfering with one another,
 scheduling resources among users,
 facilitating input/output,
 recovering from errors,
 accounting for resource usage,
 facilitating parallel operations,
 organizing data for secure and rapid access, and
 handling network communications
24
Prevalent operating systems: As already mentioned above, some of the commonly known
operating systems are UNIX, Linux, Mach, MS-DOS, MS-Windows, Windows/NT, OS/2,
MacOS etc. Some of the basic key features of these operating systems are given below for
study, knowledge and comparison.
 DOS, short for "Disk Operating System", is a shorthand term for several closely
related operating systems that dominated the IBM PC compatible market between 1981
and 1995, or until about 2000 if we include the partially DOS-based Microsoft Windows
versions 95, 98 and Millennium Edition.
DOS is a single-user, single-task operating system with basic kernel functions that
are non-re-entrant: only one program at a time can use them. There is an exception with
Terminate and Stay Resident (TSR) programs, and some TSRs can allow multitasking. The
DOS kernel provides various functions for programs, like displaying characters on-screen,
reading a character from the keyboard, accessing disk files and more.
 Microsoft Windows is a series of software operating systems and graphical user
interfaces produced by the Microsoft Company. Microsoft first introduced an operating
environment named Windows in November 1985 as an add-on to MS-DOS in response to
the growing interest in graphical user interfaces (GUIs). Microsoft Windows came to
dominate the world's personal computer market, overtaking MacOS, which had been
introduced previously. As of October 2009, Windows had approximately 91% of the
market share of the client operating systems for usage on the Internet. The NT family of
Windows systems was fashioned and marketed for higher reliability business use.
Windows 7 is the latest release of Microsoft Windows, in the series of operating
systems produced by Microsoft for use on personal computers, including home and
business desktops, laptops, net books, tablet PCs, and media center PCs. Windows 7 was
released on July 22- 2009, three years after the release of its predecessor, Windows Vista.
The most recent client version of Windows is Windows 7; the most recent server
version is Windows Server 2008 R2; the most recent mobile OS version is Windows
Mobile 6.5. Windows 8, the successor to Windows 7, is currently in development.
25
 The UNIX Operating System is available on machines with a wide range of
computing power, from microcomputers to mainframes, and on different manufacture's
machines. No other operating system can make this claim. The reasons of popularity and
success of UNIX are explained below :
Portability: The system is written in high-level language making it easier to read,
understand, change and, therefore move to other machines. The code can be changed and
compiled on a new machine. Customers can choose from a wide variety of hardware
vendors without being locked in with a particular vendor.
Machine-independence: The system hides the machine architecture from the user,
making it easier to write applications that can run on micros, minis and mainframes.
Multi-User Operations: UNIX is a multi-user system designed to support a group of
users simultaneously. The system allows for the sharing of processing power and peripheral
resources, while at the same time it provides excellent security features.
Hierarchical File System: UNIX uses a hierarchal file structure to store information.
This structure has the maximum flexibility in grouping information in a way that reflects its
natural state. It allows for easy maintenance and efficient implementation.
UNIX shell: UNIX has a simple user interface called the shell that has the power to
provide the services that the user wants. It protects the user from having to know the
intricate hardware details.
Pipes and Filters: UNIX has facilities called Pipes and Filters which permit the user
to create complex programs.
 Linux is the operating system that is now used on a majority of web servers. Linux
is an open operating system. This means the source code is freely available. Anyone
distributing machine executable versions of this code should also be able to provide the
source code. Also any changes to the source code should be available under the same
licensing conditions. Linux is mainly developed by volunteers all over the world.
Linux runs on widely differing hardware platforms ranging from small embedded
systems over commodity personal computers to huge clusters for processor intensive jobs
like scientific calculations or 3D rendering. The reasons of popularity and success of
LINUX are explained below :
Linux source code is freely distributed.
26
It has the best technical support available.
It has no vendor lock-in.
It runs on a wide range of hardware.
It is exceptionally stable.
It has the tools and applications you need.
It interoperates with many other types of computer systems.
It has a low total cost of ownership.
Check your progress (6)
Say whether true or false:-
1. Operating system is the backbone of computer system.
2. Multiuser OS allows a program to run on more than one CPU simaltanously.
3. Unix is single user OS.
1.7 Computer Languages
A language which is acceptable to the computer system is called as computer
language or programming language. computer languages are used to communicate
with computers.
Computer languages can be divided into two groups:
 high-level languages
 low-level languages.
High-level languages
High-level languages are designed to be easier to use, more abstract, and more
portable than low-level languages. Syntactically correct programs in some languages
are then compiled to low-level language and executed by the computer. Most modern
software is written in a high-level language, compiled into object code, and then
translated into machine instructions. By comparison, a high-level programming
language isolates the execution semantics of a computer architecture from the
specification of the program, which simplifies development. Programs written in
high-level languages are translated into assembly language or machine language by a
compiler. Assembly language programs are translated into machine language by a
program called an assembler.
27
Every CPU has its own unique machine language. Programs must be rewritten or
recompiled, therefore, to run on different types of computer.
Low level languages
A low-level programming language is a programming language that provides little or
no abstraction from a computer's instruction set architecture. Generally this refers to
either machine code or assembly language. The word "low" refers to the small or
nonexistent amount of abstraction between the language and machine language;
because of this, low-level languages are sometimes described as being "close to the
hardware."
Low-level languages can be converted to machine code without using a compiler or
interpreter, and the resulting code runs directly on the processor. A program written in
a low-level language can be made to run very fast, and with a very small memory
footprint; an equivalent program in a high-level language will be more heavyweight.
Low-level languages are simple, but are considered difficult to use, due to the
numerous technical details which must be remembered.
Example of Low-level programming languages are assembly language & machine
language.
Assembly language
A programming language that is once removed from a computer's machine language.
Machine languages consist entirely of numbers and are almost impossible for humans
to read and write. Assembly languages have the same structure and set of commands
as machine languages, but they enable a programmer to use names instead of
numbers.
Machine language
Machine languages are the only languages understood by computers. While easily
understood by computers, machine languages are almost impossible for humans to use
because they consist entirely of numbers. Programmers, therefore, use either a high-
level programming language or an assembly language. An assembly language
contains the same instructions as a machine language, but the instructions and
variables have names instead of being just numbers.
Check your progress (7)
Say whether true or false:-
1. Machine language and assembly language are low level language.
2. Machine language understand by computer easily.
1.8 Data processing
28
Computer data processing is any process that a computer program does to enter data
and summarize, analyze or otherwise convert data into usable information. The
process may be automated and run on a computer. It involves recording, analysing,
sorting, summarising, calculating, disseminating and storing data. Because data are
most useful when well-presented and actually informative, data-processing systems
are often referred to as information systems. Data-processing systems typically
manipulate raw data into information, and likewise information systems typically take
raw data as input to produce information as output.
Data processing may or may not be distinguished from data conversion, when the
process is merely to convert data to another format, and does not involve any data
manipulation.
Processing
Basically, data are nothing but facts (organized or unorganized) which can be
converted into other forms to make it useful, clear and pratically used. This process of
converting facts to information is called Processing. Practically all naturally occurring
processes can be viewed as examples of data processing systems where "observable"
information in the form of pressure, light, etc. are converted by human observers into
electrical signals in the nervous system as the senses we recognize as touch, sound,
and vision. Even the interaction of non-living systems may be viewed in this way as
rudimentary information processing systems.
Elements of data processing
In order to be processed by a computer, data needs first be converted into a machine
readable format. Once data are in digital format, various procedures can be applied on
the data to get useful information. Data processing may involve various processes,
including:
 Data summarization
 Data aggregation
 Data validation
 Data tabulation
 Statistical analysis
Check your progress (8)
Say whether true or false:-
1. Process of converting text in information is called data processing.
2. Manipulation of data is done during processing.
3. Data validation is process of data processing.
29
1.9 Programming
Programming is the process of writing a sequence of instructions to be excuted by a
computer to solve a problem. It is also considered as the act of writing computer
programs. Computer programs are set of instructions that tell a computer to perform
certain operations. The instructions in programs are logically sequenced and
assembled through the act of programming. Computer programming has many facets:
It is like engineering because computer programs must be carefully designed to be
reliable and inexpensive to maintain. It is an art because good programs require that
the programmer use the intuition and a personal sense of style. It is a literary effort
because programs must be understood by computers, and this requires mastery of a
programming language. Programmers are people who write programs and use
different programming language to communicate instructions to the computer.
1.9.1 Method of Problem Solving
A computer is only a problem-solving tool. It is one of the many different tools
engineers use in solving problems.
A general method of problem solving may be described by the following steps:
1. Recognize and understand the problem.
2. Accumulate facts.
3. Select appropriate theory.
4. Make necessary assumptions.
5. Solve the problem.
6. Verify results.
Performing step 5 i.e. solve the problem may involve a computer. Given below are
five steps that are followed in using a computer as a problem-solving tool:
1. Develop an Algorithm and a Flowchart.
2. Write the program in a computer language. (i.e. Fortran, C)
3. Enter the program into the computer.
4. Test and debug the program.
5. Run the program, input data, and get the results from the computer.
1.9.2 Algorithm
The programmer begins the programming process by analyzing the problem, breaking
it into manageable pieces, and developing a general solution for each piece called an
algorithm. An Algorithm is a detailed sequence of simple steps that are needed to
solve a problem. Algorithm is the set of instructions written in plain English, for
solving a problem or sub-problem in a finite amount of time using a finite amount of
30
data. An algorithm may be a verbal or written description of a logical sequence of
actions applied to objects.
Suppose a programmer needs an algorithm to determine an employee's weekly wages.
The following algorithm reflects what would be done by hand:
1. Look up the employee's pay rate.
2. Determine the hours worked during the week.
3. If the number of hours worked is less than or equal to 40, multiply the hours by the
pay rate to calculate regular wages.
4. If the number of hours worked is greater than 40, multiply 40 by the pay rate to
calculate regular wages, and then multiply the difference between the hours worked
and 40 by 1 1/2 times the pay rate to calculate overtime wages.
5. Add the regular wages to the overtime wages (if any) to determine total wages
1.9.3 Flowchart
A Flowchart is a graphical representation of an algorithm. There are many basic
symbols available to depict the various actions performed in algorithm writing. Of the
many symbols available, these 6 basic symbols are used the most:
Start/Stop
Input/Output
31
Connector (connect one part of the flowchart to another)
Process, Instruction
Document
Preparation (may be used with "do loops" )
Decision
32
Terminator
Check your progress (9)
Say whether True Or False:
1. Program is a set of instructions.
2. Graphic representation of program is called Algorithm.
3. Rectangle symbol used for start in flowchart.
Check your progress ANSWER KEY
ANSWER 1
1. Input, output, processing. 2.Input unit. 3. Memory 4.ALU
ANSWER 2
1. True. 2. False. 3. True
ANSWER 3
1. Output. 2. Computer output microfilm. 3.Plotter 4.Speech synthesizer.
ANSWER 4
1. Digitizer. 2. Bar code. 3.OCR.
ANSWER 5
33
1. True. 2. True. 3. True.
ANSWER 6
1. True. 2. False. 3.True.
ANSWER 7
1. True. 2. True
ANSWER 8
1. False. 2. False. 3. True
ANSWER 9
1. True. 2. False. 3. False
34
Unit II : Computer Programming in Fortan /C / Basic
Structure :-
2.0 Introduction
2.1 Objectives
2.2 Constants, Variables and Data types
2.2.1 C Tokens
2.2.2 Keywords and Identifiers
2.2.3 Constants
2.2.4 Variable
2.2.5 Data types
2.2.6 C Instructions
2.2.7 Declaration of Variables
2.2.8 Where variables are declared
2.2.3 Basic Structure of C Program
2.3.1 The first C Program
2.4 Operators and Expressions
2.4.1 Arithmetic Operator
2.4.2 Relational Operator
2.4.3 Logical Operator
2.4.4 Assignment Operator
2.4.5 Increment and decrement Operator
35
2.4.6 Conditional Operator
2.4.7 Bitwise Operator
2.4.8 Special Operator
2.4.9 Precedence of Operator
2.5 Console I/O Functions
2.5.1 Formatted console I/O Functions
2.5.2 Unformatted console I/O Functions
2.6 Decision making and branching
2.7 The Loop Control Structure
2.7.1 The for Loop
2.7.2 The while loop
2.7.3 The do-while loop
2.7.4 The Break Statement
2.7.5 The continue Statement
2.8 The Case Control Structure
2.8.1 The Switch Statement
2.8.2 The Goto Statement
2.9 Array
2.10 Functions
2.11 Let Us Sum up
2.12 Check your Progress : The Key
36
37
2.0 Introduction :- A language is a means of communication. We use a natural language such as
English to communicate our ideas and emotions to others. Similarly, a computer language is
a means of communication used to communicate between people and the computer. With
the help of a computer language, a programmer tells a computer what he/she wants it to
do.
In Other words ''A language that is acceptable to a computer system is called a Computer
language or programming language, and the process of writing instructions in such a
language for an already planned program is called programming or coding.
C is a programming language developed at AT & T's Bell Laboratories of USA is 1972. It was
designed and written by a Man Dennis Ritchie. C Seems so popular is because it is reliable, simple
and easy to use. Programs written in C are efficient and fast. This is due to the variety of data types
and powerful operators. Several standard functions are available which can be used for developing
programs C is highly portable. The C character Set consists of alphabets (A,B,C ---- Z, a,b,______z,
digits (0-9), Special Symbol. ( ~, (, !, @, # etc.)
2.1 Objectives :- The main aim of this unit is to study C programming language, and its
application in the field of Chemistry to solve various Problems. Steps in learning C :
Alphabets
Digits
Special
Symbol
Constants
Variables
Keywords
Instruction Program
38
After going through this unit you should be able to develop small computer codes (Program)
involving simple formulae in chemistry such as vander waals equation, Evaluation of lattice energy,
sum of n number etc.
Implementing is C language :-
2.2 Constants, Variables and Keywords :- The alphabets, numbers and special symbols when
properly combined form constants, variables and keywords. A constant is a Quantity that
doesn't change. This quantity can be stored at a locations in the memory of the computer. A
variable can be considered as a name given to the location is memory where this constant is
stored. Naturally the contents of the variables can change.
For example in the equation.
3 x + y = 20
Since 3 and 20 cannot change, they are called constants, whereas the quantities x and y can
vary or change hence are called variables.
2.2.1 C Tokens :- In a C Program the Smallest individual units are known as C tokens. C has six types
of tokens as shown in Fig. 2.1
Chemical
equation
or
formulae
Implying Using
C varibles ,
keywords and
constants
(Declartion)
Transforming
required
equation as
'C' Statements
Executing the
'C' Statements
as sequence
of Program
C Tokens
Keywords
Eg. Float
Identifiers Constants Strings Eg OperatorE Special
39
2.2.2 Keywords and Identifiers :-
Keywords :- Keywords are the words whose meaning has already been explained to the C
compiler. The keywords cannot be used as variable names because if we do so we are trying to
assign a new meaning to the keyword, which is not allowed by the computer. The keywords are also
called 'Reserved words'
There are only 32 keywords available in C. Following is the list of keywords in C.
Identifies :- Identifiers are names that are given to various program elements such as variables,
functions and array. These are user defined names and consist of a sequence of letters and digits, in
auto double int struct
break else long Switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if slatic while
40
any order, except that the first character must be a letter. Both uppercase and lowercase letters are
permitted, although lowercase letters are commonly Used. The Underscore character is also
permitted in identifiers. It is usually used as a link between two words in long identifiers.
Ex - The following names are valid identifiers.
x y12 sun1
names area Table
2.2.3 Constants :- Constants in C refer to fixed values that do not change during the execution of a
program. Constant are also called literals.
Constants
Numeric Constants Character Constants
Integer Real Single Character String
Constant Constants Constants Constants
Integer Constants :- An integer constant is an integer valued number. Thus it consists of a sequence
of digits.
Rules for constructing Integer Constants :-
1. An integer constant must have at least one digit.
2. It must not have a decimal point.
41
3. It could be either positive or negative.
4. If no sign precedes an integer constants it is assumed to be positive.
5. No commas or blanks are allowed within an integer constant.
6. The allowable range for integer constants is - 32768 to + 32767.
Ex : 426
+ 782
-8000
-7605
Real Constants :- Real constants are often called floating point constants the real constants could be
written in two forms, Fractional form and Exponential form.
Rules for Constructing Real constants :- Following rules must be observed while constructing real
constants expressed in fractional form :
1. A real constants must have at least one digit.
2. It must have a decimal point.
3. It could be either positive or negative.
4. Default sign is positive.
5. No commas or blanks are allowed within a real constants.
Ex : + 325.34
426.0
- 32.76
- 48.5792
42
The exponential form of representation of real constants is usually used if the value of the
constant is either too small or too large. It however doesn't restrict us in any way from using
exponential form of representation for other real constants.
In exponential form of representation, the real constant is represented in two parts. The
part appearing before 'e' is called mantissa, whereas the part following 'e' is called exponent.
Following rules must be observed while construction of real constants in exponential form :
1. The mantissa part and the exponential part should be separated by a letter e.
2. The mantissa part may have a positive or negative sign.
3. Default sign of mantissa part is positive.
4. The exponent must have at least one digit which must be a positive or negative integer,
Default sign is positive.
5. Range of real constants expressed in exponential form is - 3.4 e 38 to + 3.4 e 38.
Ex : + 3.2e - 5
4. 1 e 8
- 0.2e + 3
- 3.2. e - 5
Character constant :- A single character constant (or simply character constant) contains a single
character enclosed within a pair of single quote marks.
Ex :- '5', 'x', ' '
Note that the character constant '5' is not the same as the number 5. The last constant is a
blank space.
Rules for constructing Character constants :-
43
1. A character constant is either a single alphabet, a single digit or a single special symbol
enclosed within single inverted commas. Both the inverted commas should point to the left.
For example 'A' is a valid character constant whereas ‘A’ is not.
2. The maximum length of a character constant can be one character.
Ex: 'A'
'I'
'5'
'='
String Constants :- A string constant is a sequence of characters enclosed in double quotes. The
characters may be letters, numbers, special characters and blank space.
Examples are : ''Hello'', ''1987'', ''Well done'' Remember that a character constant (eg. 'x') is not
equivalent to the single character string constant (eg ''x'') further a single character string constants
does not have an equivalent integer value while a character constant has on integer value.
Backslash Character Constants :- C Supports some special backslash character constants that are
used in output function. for example the symbol 'n'' stands for newline character. A list of such
backslash character constants is given in following table. Note that each one of them represents one
character, although they consists of two characters. These characters combinations are known as
Escape sequences.
Table Backslash Character constants
Constants Meaning
'a' Audible alert (bell)
'b' backspace
'f' from feed
'n' new line
'r' carriage return
44
'v' Vertical tab
'' ' Single Quote
''' ' Double Quote
'?' Question Mark
'' Backslash
'o' null
2.2.4 Variables :- A quantity which may vary during program execution is called a variable.
A variable is a data name that may be used to store a data value. Unlike constants that
remain unchanged during the execution of a program, a variable may take different values
of different times during execution.
A variable name can be chosen by the programmer is a meaningful way so as to reflect its
function or nature in the program. Some examples of such name are :-
Average
Height
Total
Counter
Class_2
Rules for Constructing variables Names :-
1. A variable name is any combination of 1 to 8 alphabets, digits or underscore. some
compilers allow variable name whose length could be upto 40 characters. Still, it would be
safer to stick to the rule of 8 characters.
2. The first character in the variable name must be an alphabet. Some systems permit
underscore as the first character.
3. No commas or blanks are allowed within a variable name.
4. No Special Symbol other than an underscore (eg. gross_sa) can be used in a variable name.
45
5. Keyword cannot be used as a variable name. This rule means we cannot give a variable a
reserved name such as int, if.
6. The compiler treats uppercase and lowercase letters as different, although both may be
used in constructing variable names. Therefore the variable names SUM, Sum and sum are
regarded as the Separate variables in C. Usually however, Variable names in C are entirely in
lowercase.
Some examples of valid variable names are :-
John Value T_raise
Delhi X l ph_value
Mark Sum1 Distance
Invalid examples include :
123 (area)
25 cm
Further examples of variable names and their correctness are given in following table 1.1
Table 1.1 Examples of Variable Names
Variable Name Valid ? Remark
1) First_tag Valid -
2) char Not Valid char is a keyword
3) Price$ Not Valid Dollar Sign is illegal
46
4) Group one Not Valid Blank Space is not permitted
5) averagenumber Valid First Eight Characters are significant
6) int_ type Valid Keyword may be part of a name
2.2.5 Data Types :- Data types are the way to identify the type of data and associated operations
of Handling it when variables are declared of a particulars data type ; then the variable
becomes the place where the data is stored and data types is the type of value (data)stored
by the variable.A good programmer language supports the programmer by giving. Such data
types in which a control on a range of values and storage space is given to use. Finally we
can say data types determine the three things
- Memory limit
- Values Limit
- Operations Limit
Data can be classified into many types such as character, integer, real etc. Since the data to
be deal with are of many types, a programming language must provide different data types. In C
language, data types can be classified in so many ways but here we are classifying the data types
into three main categories :
1. Fundamental
2. Built in derived data type.
3. User defined derived data type.
C Data Types
Fudament
al Data
types Built in
derived
data types
User defined
derived Data
types
47
Character Structure
Integer Union
Float Array Enum Double
Pointer Typedef
Void
Generally in C four main data types are, used which may be represented differently within
the computer memory. The basic data types are :-
Data type Description Memory consumed
1. int integer Quantity 2 byte
2. char Single Character 1 byte
3. float real number 4 bytes
4. double real number with 8 bytes
more precision
Data types its format string and their Ranges
Data type Format String (Conversion
Character
Range
int % d -32768 to 32767
char % c -128 to 127
float % f - 3.4e 38 to 3.4e38
48
double % lf -1.7e 308 to 1.7e308
2.2.6 C Instructions :- Now that we have seen the different types of constants, variables and
keywords the next logical step is to learn how they are combined to form instructions. There
are basically four types of instructions in C :
1. Type declaration instruction
2. Input/Output instruction
3. Arithmetic Instruction
4. Control Instruction
The purpose of each of these instructions is given below :-
1. Type declaration Instruction :- To declare the type of variable used in a C
program.
2. Input/Output Instruction :- To perform the function of supplying input data to a
program and obtaining the output results from it.
3. Arithmetic instruction :- To perform arithmetic operations between constants
and variables.
4. Control instructions :- To control the sequence of execution of various statements
in a C program.
2.2.7 Declaration of Variables :- After designing suitable variable names, we must declare them to
the complier. Declaration does two things :
1. It tells the complier what the variable name is.
2. It specifies what types of data the variable will hold.
The declaration of variables must be done before they are used in the program.
49
Type declaration :- A variable can be used to store a value of any data type. That is, the name has
nothing to do with its type. The syntax for declaring a variable is as follows :
Data type V1, V2 - Vn,
V1, V2, ---Vn are the names of variables. Variable are separated by commas. A declaration statement
must end with a semicolon, For example, valid declarations are :
int count ;
int number, total ;
double ratio ;
char ch ;
int, double, and char are the keywords to represent integer type, real type and character type data
values respectively.
2.2.8 Where variables Are declared :- Variables will be declared in three basic places :
inside functions, in the definition of function parameters and Outside of all functions. These
are local variable, formal parameters and global variables.
Local Variables : Variable that are declared inside a function are called local variables. Local
Variables exist only while the block of code in which they are declared is executing. That is, a local
variable is created upon entry into its block and destroyed upon exit. The most common code block
in which local variables are declared is the functions.
Formal Parameters :- If a function is to use arguments, it must declare variables that will accept the
valves of the arguments. These variables are called the formal parameters of the functions. They
behave like any other local variables inside the function.
50
Check your progress 1 Notes :
i) Write your answer in the space given below.
ii) Compare your answer with those given at the end of the unit.
Fill in the Blanks.
a) A character variable can at a time store____________.
b) A C Variable cannot start with___________and__________.
c) The escape sequence character___________causes the cursor to move to the next
line on the screen.
d) Every program statement in a C program must end with a__________.
Global Variables :- Unlike local variables, global variables are known throughout the program and
may be used by any piece of code. Also, they will hold their value throughout the program's
execution. You Create global variables by declaring them outside of any function, Any expression
may access. then, regardless of what block of code that expression is in.
Basic Structure of C Program :-
Documentation Section
Link Section
Definition Section
Global Declaration Section
main ( ) Function Section
{
Declaration Part
51
The Documentation : Section consists of a set comment lines giving the name of the program, the
author and other details, Which the programmer would like to use later. The Link section provides
instruction to the complier to link functions from the system library.
The Definition Section defines all symbolic constants.
Global Declaration Section :- There are some variables that are used in more than one function.
Such variables are called global variables and are declared in the global declaration section that is
outside of all the functions. This section also declares all the user defined functions.
Every C Program must have one main ( ) function section. This section contains two parts,
declaration part and executable part.
The declaration part declares all the variables used in the executable part. There is at least
one statement in the executable part. These two parts must appear between opening and the
closing braces. The program execution begins at the opening brace and ends at the closing brace.
The closing brace of the main function section is the logical end of the program. All statements in the
declaration and executable parts end with a Semicolon.
Function 1
Function 2
'
Function N
52
The Subprogram Section contains all the user defined functions that are called in the main (
) function. User defined functions are generally placed immediately after the main ( ) function,
although they may appear is any order.
All sections, except the main () function section may be absent when they are not required.
2.3.1 The First C Program :- Each instruction is a C Program is written as a Separate statement.
Therefore a complete C program is written as a separate statement. Therefore a complete C
Program will comprise of a series of statements. These statements must appear in the same
order in which we wish them to be executed ; unless of course the logic of the problem
demands a deliberate 'jump' or transfer of control to a statement which is out of sequence.
However big a program, the following rules are applicable to all C Statements :
1. Blank spaces may be inserted between two words to improve the readability of the
statement. However, no blank spaces are allowed within a variable, constant or keyword.
2. Usually all statements are entered in Small case letters.
3. C has no specific rules for the position at which a statements is to be written. That's why it is
often called a Free - Form Language.
4. Any C statements always ends with a ; (Semicolon).
Let us now write down a simple C program to Calculate simple interest.
/ * Calculation of Simple Interest * /
main ( )
{
int p, n ;
float r, si ;
P = 1000 ;
n = 3 ;
r = 8.5 ;
53
si = (P * r * n) / 100 ;
printf (''Simple interest = %f'', si) ;
}
This program when executed will produce the following output.
Now a few useful tips about the program.
- Comment about the program should be enclosed within /* * /. For example the first
statement in our program are comments.
- Any number of comments can be given at any place in the program.
- Comment cannot be nested. For example
/*Cal of SI/*Author san date 11/11/11 */*/.
- A Comment can be split over more than one line, as in,
/* This is
a jazzy
comment */
Although a lot of comments are probably not necessary in this program, it is usually the case that
programmers tend too many. Comments should be used at any place where there is a possibility of
confusion.
- Any C Program is nothing but a combination of functions. main ( ) is one such function.
Empty parentheses after main are necessary and they are indicating that the function main
has no arguments or parameters. (The concepts of parameters will be discussed in detail
later when we discuss function).
Simple Interest = 255.000000
54
The main ( ) is a special function used by the C system to tell the computer where the
program starts. Every program must have exactly one main function, If we use more than one main
function, the complier cannot tell which one marks the beginning of the program.
- The set of statements belonging to a function are enclosed within a pair of braces. For
example,
main ( )
{
Statements 1 ;
Statement 2 ;
Statement 3 ;
}
- Any variable used in the program must be declared before using it.
For example.
int p, n ;
float r, si ;
- Any C statements always ends with a ; (Semicolon) For example,
float r, si ;
r = 8.5 ;
- In the statements
Si = (P* r* n) / 100 ;
* and / are the arithmetic operators.
- printf ( ) is a predefined standard C function for printing output. Predefined complied means
that it a function that has already been written and linked together with our program at the
time of linking.
55
- printf ( ) is a function which is used to print on the screen the value contained is a variable.
The general form of
printf ( ) statement is
printf (''<Format String'', <list of variables>) ;
printf (''message'') ;
Above two general form of printf can be merged.
For Example,
printf (''Simple interest = %f'', si) ;
The output of
printf ('' Principal = % d n Rate = % f'', P,r ) ;
would look like Principal = 1000
Rate = 8.5
What is 'n' doing is the above printf statement ?
It is called newline and it takes the cursor to the next line. Therefore, you get the output split
over two lines. 'n' is one of the several escape sequences available in C.
2.4 Operator and Expressions :- An Operator is a symbol that perform specific mathematical or
logical manipulations in program. Operators are used in Programs to manipulate data and
variable. They usually form a part of the mathematical or logical expressions.
C Operators can be classified into a number of categories. They include :
1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Assignment Operator
5. Increment and decrement operators
56
6. Conditional Operators
7. Bitwise Operators
8. Special Operators
Operand :- An Operand is a constant value or Variable on which operator performs the operation.
An Operator cannot perform any operation without operand. To perform on operation, an operator
requires at least one operand. On the basis of operand used in the expression ; we can categories
the operators in another way.
- Unary Operator :- That operates on a single operand.
- Binary Operator :- When operator requires at least two operands to perform its specific
operation then is called Binary operator.
- Ternary Operator :- When Operator requires at least three operands to perform its
specific operation then it is called Ternary operator.
2.4.1 Arithmetic Operator :- Symbols that are used to perform or represent arithmetic operations
are known as Arithmetic Operator some arithmetic operations and their operators are given
in the following table.
Operator Meaning
+ Addition or Unary Plus
- Subtraction or Unary minus
* Multiplication
/ Division
% Modulo Division
Integer division truncates any fractional part The modulo division operation produces the
remainder of an integer division. Examples of use of arithmetic operators are :
57
a - b a + b
a x b a / b Here a and b are operands.
. The modulo division operator cannot be used on floating point data.
Arithmetic Expression : is a combination of variables, constants and operators arranged as per the
syntax of the language.
2.4.2 Relational Operators :- The operators proceed about the relationship between two
operands are known as relational operators. There are the binary operators that compare
the values of both operands aside itself.
An expression such as a < b or 1 < 20 containing a relational operator is termed as a
relational expression. The value of a relational expression is either one or zero. It is one if the
specified relation is true and zero if the relation is false.
For example
10 < 20 is true
but 20 < 10 is false
C Supports six relational operators These operators and their meaning are shown in table.
Operator Meaning
< is less than
< = is less than or equal to
> is greater than
> = is greater than or equal to
58
= = is equal to
! = is not equal to
A simple relational expression contains only one relational operator and takes the following form:-
ae -1 relational operator ae - 2
ae - 1 and ae - 2 are arithmetic expression, which may be simple constants, variables or combination
of them. Given below are some examples of simple relational expression end their values :
4.5 < = 10 True
4.5 < = 10 False
-35 > = 0 False
10 < 7 + 5 True
a + b = = c + d True only if the sum of values of a and b is equal to the sum of values of c and
d.
When arithmetic expressions are used on either side of a relational operator, the arithmetic
expressions will be evaluated first and then the results compared. That is, arithmetic operators have
a higher priority over relational operators.
Relational expressions are used in decision statement such as if and while to decide the
course of action of a running program.
2.4.3 Logical Operators :- To form the Complex relational expressions we use the logical operators
&& (And) and || (OR) they work as connectors for more than one expression to make
comparison more precise. There are three types of logical operators.
Symbol Name Meaning
1. & & Logical AND True when all conditions are true
59
2. || Logical OR True when one of them is true.
3. ! Logical Not Negation
The logical operator && and || are used when we want to test more than one condition and
make decisions. An example is :
a > b && x = = 10
An expression of this kind, which combines two or more relational expressions, is termed as
a logical expression or a compound relational expression.
2.4.4 Assignment Operator :- The operators are used to assigning a value of variable, constant or
expression to a variable, known as Assignment Operators.
The General form of the assignment operator is.
Variable_name = expression ;
Where an expression may be as simple as a single constant or as complex as you require.
Ex : a = 5 ;
An expression of the form variable = expression is called as assignment expression and when it is
followed by the semicolon ( ; ) it is called as assignment statement.
Compound Assignment Operators :- For compounding the expression compound assignment
operators are Used C contains the following five compound assignment operators +=, - =, *=, /= and
% = To see how they are used, consider the first operator +=,
The assignment expression
expression 1 + = expression 2 ;
is equivalent to
expression 1 = expression 1 + expression 2 ;
60
Example :- a + = 5 ;
is equivalent to a = a + 5 ;
and so on for all five operators.
Usually expression 1 is an identifiers.
2.4.5 Increment and Decrement Operators :- C allow two very useful operator not generally
found in other languages. These are the increment and decrement operators : ++ and --.
The Operator ++ Order adds 1 to the operand, while -- Subtracts 1, Both are unary operators
and takes the following form :
++ m ; or m ++ ;
- - m ; or m --;
Prefix Notation :- In prefix form operator Occurs before the operand.
Postfix Notation :- In Postfix form operator occurs after the operand.
While ++ m and m++ mean the same thing when they form statements independently, they behave
differently when they are used in expressions on the right - hand side of an assignment statement.
Consider the following :-
m = 5 ;
y = ++ m ;
In this case, the value of y and m would be 6. Suppose, If we rewrite the above statements as
m = 5 ;
y = m + + ;
then, the value of y would be 5 and m would be 6. A Prefix Operator first adds 1 to the operand and
then the result is assigned to the variable on left. On the other hand, a postfix Operator first assigns
the value to the variable on left and then increments the operand.
61
Rules for ++ and -- Operators :-
1. Increment and decrement operators are unary operators and they require variable as
their operands.
2. When postfix ++ (or--) is used with a variable is an expression, the expression is evaluated
first using the original value of the variable and then the variable is incremented (or
decrement) by one.
3. When prefix ++ (or --) is used in an expression, the variable is incremented (or
decrement) first and then the expression is evaluated using the new value of the variable.
4. The precedence and associatively of ++ and -- operators are the same as those of
unary + and Unary -.
2.4.6 Conditional Operator :- A ternary operator pair ''? :'' is available in C to construct
conditional expression of the form.
exp 1 ? exp 2 : exp 3
Where exp1, exp2 and exp3 are expression The Operators ? : Works as follows :-
exp1 is evaluated first. If it is nonzero (true) the exp2 is evaluated and becomes the valve of the
expression, IF expl is False, exp3 is evaluated and its valve becomes the value of the expression. Not
that only one of the expression (either exp2 or exp3) is evaluated.
For example, consider the following statements
a = 10 ;
b = 15 ;
x = (a > b) ? a : b ;
2.4.7 Bitwise Operators :- C has a die of supporting special operators known as bitwise operators
for manipulation of data at bit level. These operators are used for testing the bits, or shifting
them right or left. Bitwise operators may not be applied to float or double.
62
Table : Bitwise Operators
Operator Meaning
& Bitwise AND
! Bitwise OR
^ Bitwise Exclusive OR
<< Shift left
>> Shift right
2.4.8 Special Operators :- C Supports Some Special operators of interest such as Comma Operator
and Size of Operator.
Comma Operators :-The Comma Operator can be used to link the related expression
together. A comma linked list of expressions are evaluated left to right and the valve of right
most expression is the value of right most expression is the value of the combined
expression. For Example, the statement
Value = (x = 10, y = 5, x + y) ;
First assigns the value 10 to x, then assigns 5 to y, and finally assigns 15 (i.e. 10 + 5) to value.
Since comma operator has the lowest precedence of all operators, the parentheses are necessary.
The size of Operator :- The size of is a compile time operator and, when used with an operand, it
returns the number of bytes the operand occupies. The operand may be a variable, a constant or a
data type Qualifier.
Examples : m = sizeof (Sum) ;
n = sizeof (long int) ;
k = sizeof (235.5) ;
63
The sizeof Operator is normally used to determine the lengths of arrays and structures when their
sizes are not known to the programmer. It is also used to allocate memory space dynamically to
variables during execution of a program.
2.4.9 Precedence of Operators :- The order or priority in which the operations are performed in
an expression is called precedence.
Hierarchy of Operations :- The priority of precedence in which the operations in an arithmetic
statement are performed is called the hierarchy of operations. The hierarchy of commonly used
operators is shown in following table :
Priority Operators Description
Ist / * % Division, multiplication, Modular division
2nd + - Addition, Subtraction
3rd = Assignment
Now a few tips about usage of operators in general.
a) In case of a tie between operations of same priority preference is given to the operator
which occurs first. for example Z = a * b + c/d ; Here a * b will be performed before c/d
even though * and / has same or equal priority, This is because * appears prior to the /
operation.
b) If there are more than one set of parentheses the operations within the innermost
parentheses will be performed first, followed by the operations within the second innermost
pair and so on.
c) We must always remember to use pairs of parentheses. A careless imbalance of the right
and left parentheses is a common error.
Example :- Determine the hierarchy of operations and evaluate the following expression ;
i = 2 * 3/4 + 4/4 + 8-2 + 5/8
64
Stepwise evaluation of this expression is shown below :-
i = 2 * 3/4 + 4/4 + 8 - 2 + 5/8
i = 6/4 + 4/4 + 8 - 2 + 5/8 Operation : *
i = 1 + 4/4 + 8 - 2 + 5/8 Operation : /
i = 1 + 1 + 8 - 2 + 5/8 Operation : /
i = 1 + 1 + 8 - 2 + 0 Operation : /
i - 2 + 8 - 2 + 0 Operation : +
i = 10 - 3 + 0 Operation : +
i = 8 + 0 Operation : -
i = 8 Operation : +
Note that 6/4 gives 1 and not 1.5 This so happens because 6 and 4 both are integers and
therefore would evaluate to only an integer constant. Similarly 5/8 evaluates to zero, since 5 and 8
are integer constants and hence must return an integer value.
2.5 Console I/O Functions :- Functions to receive input from keyboard and write output to VDU
are known as console I/O Functions. This can be classified into two categories : Formatted
Check your progress 2
Notes : i) Write your answer in the space given below.
ii) Compare your answer with those given at the end of the unit.
Determine the hierarchy of operations and evaluate the following expression :
KK = 3/2 * 4 + 3/8 + 3
65
and Unformatted console I/O functions. The basic difference between them is that the
formatted as per our requirements. For example, if values of average marks and percentage
marks are to be displayed on the screen, the detail like where this output would appear on
the screen, then the details like where this output would be present between the two
values, the number of places after the decimal points etc. can be controlled using formatted
functions. The functions available under each of these two categories are shown in figure
2.2.
Fig 2.2
2.5.1 Formatted Console I/O Functions :- As can be seen from figure 2.2 the functions printf ( )
and scanf( ) fall under the category of formatted console I/O Functions. These functions
allow us to supply the input in a fixed format and let us obtain the output in the specified
form.
printf Function :- The general form of Printf Statement is
Console Input/Output Fnuctions
Formatted Functions
Type Input Output
char scanf() printf( )
int scanf() printf( )
float scanf() printf( )
double scanf() printf()
Unformatted Functions
Type Input Output
Char getch() putch( )
getche() putchar( )
getchar()
String gets() puts()
66
printf (''Format String'', list of variables).
or
printf (''Control String'', arg1, ang2........argn) ;
The format string (Control String) consists of three types of items :-
1. Characters that will be printed on the Screen as they appear.
2. Format Specifications that define the output format for display of each item.
3. Escape Sequence characters such asn,t andb.
The Control String indicates how many arguments follow and what their types are. The
arguments arg1, arg2...........argn are the variables whose values formatted and printed according to
the specification of the control string. The arguments should match in number, order and type with
the format specifications.
Examples of printf () Statement are :-
1. printf (''Programing in C'');
2. printf ('' %d'', x) ; where x is a integer variable.
3. printf (''Sum = % f'', total) ; Where total is a float variables.
4. printf ('' n'') ;
scanf () Functions :- The general form of Scanf ( ) Statements is as follows :-
scanf (''format string'', list of addresses of variables) ;
or
scanf (''Control String'', ang1, ang2..........angn) ;
67
The Control String Specifies the field format in which the data is to be entered and the
arguments arg1, arg2........................., argn, Specify the address of locations where the data is stored.
control string and arguments are separated by Commas.
Control string (also known as format string) contains field specifications, which direct the
interpretation of input data. It may include :
- Field (or format) specifications, consisting of the conversion character %, a data type
character (or type specifies), and an optional number, specifying the field width.
- Blanks, tabs or newlines.
Blanks, tabs and newlines are ignored The data type character indicates the type of data that
is to be assigned to the variable associated with the corresponding argument. The field width
specifier is optional.
For Example :- Scanf (''%d% f%c'', &ab, &b, &ch);
where int ab ;
float b ;
char ch ;
Note that we are sending addresses of variables (addresses are obtained by using & the address of
operator) to scanf () function. This is necessary because the values received from keywords must be
dropped into variables corresponding to these addresses.
2.5.2 Unformatted Console I/O Functions :- There are several standard library functions available
under this category - those which can deal with a single character and those which can deal with a
string of character.
(i) getchar () Function :- Reading a single character can be done by using the function getchar.
The general form of getchar () function is as follows :-
Variable _ Name = getchar () ;
68
Variable name is a valid C name that has been declared as char type. When this statement is
encountered, the computer waits until a key is pressed and then assigns this character as a
value to getchar () function, since getchar() is used on the right hand side of an assignment
statement, the character value of getchar ( ) is in turn assigned to the variable name on the
left. For example
char Name ;
Name = getchar ( );
will assigns the character 'H' to the variable name when we press the key 'H' on the
keyboard.
(ii) putchar ( ) Function :- It is used for writing character one at a time to the Screen. The
general form of putchar ( ) function is as follows.
putchar (Variable Name) ;
Where variable name is a type char variable containing a character. This statement displays
the character contained in the variable name at the terminal (Screen). For example, the
statements
char answer = 14' ;
putchar (answer) ;
Will display the character 4 on the Screen.
2.6 Decision making and Branching :- A decision control instruction can be implemented in C
using :
(a) The if statement
69
(b) The if-else statement
(c) The Conditional Operators
These statements are popularly known as Decision making statements. Since these
statement control the flow of execution, they are also known as control statements.
(a) The if statement :- C uses the keyword if to implement the decision control instruction. The
general form of if statement looks like this :
if (test expression)
{
Statement - block ;
}
The statement block may be a single statement or a group of statements. If the test
expression is true, the statement block will be executed ; otherwise the statement block will
be skipped and the execution will jump to the next statement. Remember, when the
condition is true both the statement block and the next statement are executed in
sequence.
(b) The if.....else statements :- The if-else statement is an extension of the simple if statement.
The general form is.
if (test expression)
{
True- block statements (s)
}
else
70
{
False - Block Statement (s)
}
If the test expression is true, then the true block statements (s), immediately following the if
statements are executed ; otherwise, the false - block statement (s) are executed. In either
case, either true-block or false-block will be executed, not both.
Example :-
Write a program to find given number is even or ODD.
main ( )
{
int num ;
printf (''Enter any Number'') ;
scanf (''%d''', &num) ;
if (num % 2 = = 0)
{
printf (''Even number'').
}
else
{
printf (''ODD Number'') ;
}
getch ( ) ;
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous
Msc chemistry previous

More Related Content

What's hot

Molecular Weight of Polymers
Molecular Weight of PolymersMolecular Weight of Polymers
Molecular Weight of Polymers
Kudzai Hamish Ruzvidzo
 
Franck Condon Principle
Franck Condon Principle Franck Condon Principle
Franck Condon Principle
SPCGC AJMER
 
Addition polymerization, its examples and uses
Addition polymerization, its examples and usesAddition polymerization, its examples and uses
Addition polymerization, its examples and uses
Ramsha Afzal
 
Copolymerisation
CopolymerisationCopolymerisation
Copolymerisation
SHUBHAMPRASAD61
 
Types of polymerization
Types of polymerizationTypes of polymerization
Types of polymerization
Farhan ullah baig
 
polymer
polymerpolymer
polymer
Amit kumar
 
Absorption shifts (Chromophores and Auxophores Concept)
Absorption shifts (Chromophores and Auxophores Concept)Absorption shifts (Chromophores and Auxophores Concept)
Absorption shifts (Chromophores and Auxophores Concept)
Dr Duggirala Mahendra
 
Spectroscopy
Spectroscopy   Spectroscopy
Spectroscopy
LIFE SCIENCES
 
Electronic spectra.ppt
Electronic spectra.pptElectronic spectra.ppt
Electronic spectra.ppt
DivyaRajGurung
 
Racemic modification (2)
Racemic modification (2)Racemic modification (2)
Racemic modification (2)
DILIP DAVHARE
 
Rigid rotators
Rigid rotatorsRigid rotators
Rigid rotators
FatimaSyed32
 
Spin spin splitting (n+1 Rule) NMR spectroscopy
Spin spin splitting (n+1 Rule) NMR spectroscopySpin spin splitting (n+1 Rule) NMR spectroscopy
Spin spin splitting (n+1 Rule) NMR spectroscopy
HumnaMehmood
 
IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...
IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...
IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...
Dr. UMESH KUMAR SHARMA
 
Uv visible-spectroscopy
Uv visible-spectroscopy Uv visible-spectroscopy
Uv visible-spectroscopy
Protik Biswas
 
Polymers
Polymers Polymers
Polymers
Suraj Khali
 
Liquid drop model
Liquid drop modelLiquid drop model
Liquid drop model
Shraddha Madghe
 
Polymer classification
Polymer classificationPolymer classification
Polymer classification
Asif Ahmed TONMOY
 
Glass transition temperature
Glass transition temperatureGlass transition temperature
Glass transition temperature
chemnidhi
 
Crystal Field Theory (CFT)
Crystal Field Theory (CFT)Crystal Field Theory (CFT)
Crystal Field Theory (CFT)
ڈاکٹر محمد اسلم عطاری
 

What's hot (20)

Molecular Weight of Polymers
Molecular Weight of PolymersMolecular Weight of Polymers
Molecular Weight of Polymers
 
Nmr 2
Nmr 2Nmr 2
Nmr 2
 
Franck Condon Principle
Franck Condon Principle Franck Condon Principle
Franck Condon Principle
 
Addition polymerization, its examples and uses
Addition polymerization, its examples and usesAddition polymerization, its examples and uses
Addition polymerization, its examples and uses
 
Copolymerisation
CopolymerisationCopolymerisation
Copolymerisation
 
Types of polymerization
Types of polymerizationTypes of polymerization
Types of polymerization
 
polymer
polymerpolymer
polymer
 
Absorption shifts (Chromophores and Auxophores Concept)
Absorption shifts (Chromophores and Auxophores Concept)Absorption shifts (Chromophores and Auxophores Concept)
Absorption shifts (Chromophores and Auxophores Concept)
 
Spectroscopy
Spectroscopy   Spectroscopy
Spectroscopy
 
Electronic spectra.ppt
Electronic spectra.pptElectronic spectra.ppt
Electronic spectra.ppt
 
Racemic modification (2)
Racemic modification (2)Racemic modification (2)
Racemic modification (2)
 
Rigid rotators
Rigid rotatorsRigid rotators
Rigid rotators
 
Spin spin splitting (n+1 Rule) NMR spectroscopy
Spin spin splitting (n+1 Rule) NMR spectroscopySpin spin splitting (n+1 Rule) NMR spectroscopy
Spin spin splitting (n+1 Rule) NMR spectroscopy
 
IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...
IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...
IR - Spectroscopy, theory, modes of vibration and sample handling. by Dr. Ume...
 
Uv visible-spectroscopy
Uv visible-spectroscopy Uv visible-spectroscopy
Uv visible-spectroscopy
 
Polymers
Polymers Polymers
Polymers
 
Liquid drop model
Liquid drop modelLiquid drop model
Liquid drop model
 
Polymer classification
Polymer classificationPolymer classification
Polymer classification
 
Glass transition temperature
Glass transition temperatureGlass transition temperature
Glass transition temperature
 
Crystal Field Theory (CFT)
Crystal Field Theory (CFT)Crystal Field Theory (CFT)
Crystal Field Theory (CFT)
 

Similar to Msc chemistry previous

Fundamental units of computer
Fundamental units of computerFundamental units of computer
Fundamental units of computerSandeep Menon
 
Basic organisation of computer system
Basic organisation of computer systemBasic organisation of computer system
Basic organisation of computer system
Parvathy Ashok
 
Basics of Computer.pdfnsbsjsjsjsjshsnssjjs
Basics of Computer.pdfnsbsjsjsjsjshsnssjjsBasics of Computer.pdfnsbsjsjsjsjshsnssjjs
Basics of Computer.pdfnsbsjsjsjsjshsnssjjs
nassorokayanda9412
 
Ch1
Ch1Ch1
Ch1
Abebe17
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
 
Basic concepts of computer & net work (1.25 mb)
Basic concepts of computer & net work (1.25 mb)Basic concepts of computer & net work (1.25 mb)
Basic concepts of computer & net work (1.25 mb)
IMRAN KHAN
 
ICT-1.pptx
ICT-1.pptxICT-1.pptx
ICT-1.pptx
Dipon11
 
Ise iv-computer organization [10 cs46]-notes new
Ise iv-computer  organization [10 cs46]-notes newIse iv-computer  organization [10 cs46]-notes new
Ise iv-computer organization [10 cs46]-notes newdilshad begum
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptx
kanwal74
 
COMMUNICATION & COMPUTER SKILLS
COMMUNICATION & COMPUTER SKILLSCOMMUNICATION & COMPUTER SKILLS
COMMUNICATION & COMPUTER SKILLS
Makaha Rutendo
 
Functional units of computer
Functional units of computerFunctional units of computer
Functional units of computer
gaurav jain
 
Computer Fundamental.pdf
Computer Fundamental.pdfComputer Fundamental.pdf
Computer Fundamental.pdf
DagneDegefu
 
Computer fundamentals
Computer fundamentalsComputer fundamentals
Computer fundamentals
HarwinderKaur53
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computersSid1256
 
Lesson 1 anatomy of a digital computer (230 kb)
Lesson 1  anatomy of a digital computer (230 kb)Lesson 1  anatomy of a digital computer (230 kb)
Lesson 1 anatomy of a digital computer (230 kb)
IMRAN KHAN
 
Computer and it's parts
Computer and it's partsComputer and it's parts
Computer and it's parts
Ashokkumar Rai
 
Computer-System-pratibha.pdf
Computer-System-pratibha.pdfComputer-System-pratibha.pdf
Computer-System-pratibha.pdf
Pratibha Sagar
 
ComputerFundementals.pptx
ComputerFundementals.pptxComputerFundementals.pptx
ComputerFundementals.pptx
AyyappanSri
 
unit-i.pdf
unit-i.pdfunit-i.pdf
unit-i.pdf
RISHI643981
 

Similar to Msc chemistry previous (20)

Fundamental units of computer
Fundamental units of computerFundamental units of computer
Fundamental units of computer
 
Basic organisation of computer system
Basic organisation of computer systemBasic organisation of computer system
Basic organisation of computer system
 
Basics of Computer.pdfnsbsjsjsjsjshsnssjjs
Basics of Computer.pdfnsbsjsjsjsjshsnssjjsBasics of Computer.pdfnsbsjsjsjsjshsnssjjs
Basics of Computer.pdfnsbsjsjsjsjshsnssjjs
 
Ch1
Ch1Ch1
Ch1
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
 
Basic concepts of computer & net work (1.25 mb)
Basic concepts of computer & net work (1.25 mb)Basic concepts of computer & net work (1.25 mb)
Basic concepts of computer & net work (1.25 mb)
 
ICT-1.pptx
ICT-1.pptxICT-1.pptx
ICT-1.pptx
 
Ise iv-computer organization [10 cs46]-notes new
Ise iv-computer  organization [10 cs46]-notes newIse iv-computer  organization [10 cs46]-notes new
Ise iv-computer organization [10 cs46]-notes new
 
Introduction to computer.pptx
Introduction to computer.pptxIntroduction to computer.pptx
Introduction to computer.pptx
 
COMMUNICATION & COMPUTER SKILLS
COMMUNICATION & COMPUTER SKILLSCOMMUNICATION & COMPUTER SKILLS
COMMUNICATION & COMPUTER SKILLS
 
Functional units of computer
Functional units of computerFunctional units of computer
Functional units of computer
 
Computer Fundamental.pdf
Computer Fundamental.pdfComputer Fundamental.pdf
Computer Fundamental.pdf
 
Computer fundamentals
Computer fundamentalsComputer fundamentals
Computer fundamentals
 
Fp203 chp1.1
Fp203 chp1.1Fp203 chp1.1
Fp203 chp1.1
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computers
 
Lesson 1 anatomy of a digital computer (230 kb)
Lesson 1  anatomy of a digital computer (230 kb)Lesson 1  anatomy of a digital computer (230 kb)
Lesson 1 anatomy of a digital computer (230 kb)
 
Computer and it's parts
Computer and it's partsComputer and it's parts
Computer and it's parts
 
Computer-System-pratibha.pdf
Computer-System-pratibha.pdfComputer-System-pratibha.pdf
Computer-System-pratibha.pdf
 
ComputerFundementals.pptx
ComputerFundementals.pptxComputerFundementals.pptx
ComputerFundementals.pptx
 
unit-i.pdf
unit-i.pdfunit-i.pdf
unit-i.pdf
 

More from mshoaib15

Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
mshoaib15
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
mshoaib15
 
Bsc math previous exam quetions
Bsc math previous exam quetionsBsc math previous exam quetions
Bsc math previous exam quetions
mshoaib15
 
Function
FunctionFunction
Function
mshoaib15
 
Computer lab (programs)
Computer lab (programs)Computer lab (programs)
Computer lab (programs)
mshoaib15
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
mshoaib15
 
Boolean expression org.
Boolean expression org.Boolean expression org.
Boolean expression org.
mshoaib15
 
Number system....
Number system....Number system....
Number system....mshoaib15
 

More from mshoaib15 (8)

Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
 
Bsc math previous exam quetions
Bsc math previous exam quetionsBsc math previous exam quetions
Bsc math previous exam quetions
 
Function
FunctionFunction
Function
 
Computer lab (programs)
Computer lab (programs)Computer lab (programs)
Computer lab (programs)
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
 
Boolean expression org.
Boolean expression org.Boolean expression org.
Boolean expression org.
 
Number system....
Number system....Number system....
Number system....
 

Recently uploaded

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 

Msc chemistry previous

  • 1. 1 Unit I Introduction to computer and computing 1.0 Introduction 1.1 Objective 1.2 Basic structure and functioning 1.3 Types of Memory 1.4 I/O devices 1.4.1 Input devices 1.4.1.1 Keyboard 1.4.1.2 Point and draw devices 1.4.1.3 Data scanning devices 1.4.1.4 Digitizer 1.4.1.5 Electronic card reader 1.4.1.6 Voice recognition device. 1.4.1.7 Vision input system 1.4.1.8 Myc 1.4.2 Output devices 1.4.2.1 Monitor 1.4.2.2 Printer 1.4.2.3 Plotter 1.4.2.4 Computer output microfilm 1.4.2.5 Screen Image Projector 1.4.2.6 Voice response system 1.5 Storage Devices. 1.5.1 Magnetic tape 1.5.2 Hard disk 1.5.3 Floppy disc 1.5.4 Compact disc 1.5.5 Video CD 1.5.6 Zip drive 1.5.7 DVD 1.5.8 DVD-RW 1.6 Operating system 1.7 Computer languages 1.8 Data processing 1.9 Principles of programming 1.9.1Method of problem solving 1.9.2 Algorithm 1.9.3 Flowchart Check your progress Answer key
  • 2. 2 1.0 Introduction The basic logical structure of the computer based on the stored program concept, as proposed by Von Neumann, has not changed over the years; though the size, shape, performance reliability and cost of computer have all changed. All computer systems perform the following five basic operations: inputting i.e. the process of entering data and instructions into the computer system; storing i.e. saving data and instructions so that they are available for initial or for additional processing as and when required; processing i.e. performing arithmetic operations (add, subtract, multiply and divide etc.); outputting and controlling. In this chapter we will discuss about all of the above basic functions of the computer and its associated topics. 1.1 Objective The goal of this unit is to familiarize you with the computer system . We will be studying about the following : 1. The functions performed by computer system. 2. I/O devices. 3. Storage devices and the different types of memory. 4. Operating system concept and its goals. 1.2 Basic structure and functioning of a computer A computer or a computer system is basically an electronic machine that can carry out specific tasks by following sequences of instructions within a program. A program includes such a sequence of instructions together with the data definition. The computer executes the program by performing one instruction after the other in the specified order. The programmer or any computer user needs knowledge of the basic computer architecture concepts to clearly understand the structure of the computer, so as to be able to use the computer or develop solutions to problems, and to use the computer as a tool to execute the solutions to his problems. All computer systems perform the fundamental functions i.e. input, processing, and output. Input involves entering data into the computer for processing. Data is entered into the computer with an input device (for example, the keyboard). Processing executes the instructions in memory to perform some transformation and/or computation on the data in the computer's memory. This emphasizes the fact that the instructions and data must be located in memory in order for the processing to proceed.
  • 3. 3 Output involves transferring data from the computer to an output device such as the computer screen or monitor. Mainly there are two types of computers. They are digital and analog computer. The basic differences between the two types are given below: Analog Digital 1. It processes analog signals 1. It processes numbers 2. Accuracy is limited 2. It has unlimited accuracy 3. Operation is performed by very few devices 3. Operation is performed by many devices 4. Basic building blocks are amplifiers 4. Basic building blocks are logic gates A computer automatically performs arithmetic & logic operation and gives output. It consists of 5 functional units, which are as follows: - 1. Input 2. Output 3. Memory 4. C.U 5. A.L.U 1. Input: - The computer accepts coded information through input devices. The most well known input device is the keyboard, which is electronically, connected to the CPU. Many other kinds of input devices are also available such as joysticks, track ball and mouse. 2. Memory: - The function of the memory is to store data and program. 3. Output: -The output is the counterpart of the input device. Its function is to send processed data to the outside world. Such output devices are monitor, printer, plotters etc. 4. Control unit: - Its function is to control the functions of input and output devices. The C.U. is effectively the nerve centre that sends control signals to other units and senses their states. Data transfer between the processor and memory is controlled by the C.U. through timing signals. A large set of wires carries the signals to all units. 5. Arithmetic and Logic unit (A.L.U): -Most computer operations are executed in the A.L.U of the processor. Any other operation is initiated by bringing the required operands into the A.L.U where the necessary operations are performed.
  • 4. 4 Basic operational concepts: - The following block diagram shows flow of signals and data between the various units of the computer. Input unit The input unit links the external environment with the computer. Data and instructions are entered into the computer through the input device. Input unit transfers input data into machine language i.e. binary code. Following functions are performed by an input unit. 1. It accepts the list of instructions and data from the outside world. 2. It converts these instructions and data in computer acceptable form. 3. It supplies the converted instructions and data to the computer system for further processing. Output Unit The output unit links the computer system with the external environment. It gives us information, which is obtained as a result of data processing as computer work with binary code. The result produced is also in the binary form. Hence it must be converted in human readable form and this task is accomplished by the output interface. Following functions are performed by an output unit:
  • 5. 5 1. It accept the result produced by computer. 2. It converts these coded result to human acceptable(readable) form. 3. It supplies the converted results to the outside world. Storage unit The data and instructions that are entered into the computer system through input units have to be stored inside the computer before the actual processing starts. Similarly, the result produced by the computer after processing is also kept somewhere inside the computer system before being passed onto the output unit. The intermediate result produced by the computer must also be preserved for ongoing processing, the storage unit of computer system is designed to serve all these needs. It provides space for storing data and instructions space for intermediate result and also space for the final result. In short the functions of the storage unit are : 1. It stores (receives) the data to be processed and instructions required for processing. 2. It stores the intermediate result of processing. 3. It also stores the final result of processing before these results are released to an output device. The storage unit of all computers comprises of the following two types of storage: Primary Storage:- The primary storage is also known as the main memory. It stores pieces of program instructions and data, intermediate results of processing and the recently produced result of processing of the job on which computer system was working currently. CPU accesses the result with very fast speed. The primary memory is volatile and its contents disappear when the computer is powered off. Secondary storage:- Secondary storage is also known as auxiliary storage. The secondary storage is used to supplement the limited storage and volatile characteristics of primary storage. It is cheaper than primary storage, and can retain information even after the computer system is switched off. Central Processing Unit The Control unit and arithmetic and logic unit of the computer system together make the CPU i.e. Central processing unit. The CPU is the brain of the computer system. CPU is also responsible for activating and controlling the operations of other units of the computer system. Arithmetic logic unit:- Actual execution of the instructions takes place in the arithmetic and logic unit. The calculations and comparisons and other decision making is performed in the ALU.
  • 6. 6 Control Unit:- Control unit maintains order and directs the operation of the entire system. The control unit acts as the central nervous system for the other components of the computer system. Check your progress (1) Fill in the blank:- 1. ..............................., ......................., ...............................,is fundamental function of computer. 2. ...............................,unit accept data from outside world. 3. ................................,stores data. 4. Arithmatic nd logical operation done in.........................unit. 1.3 Types of Memory Every computer has storage space known as memory. There are two types of memory 1. Main memory or Primary memory 2. Secondary memory or auxiliary memory. Primary memory is of the following types:- 1. RAM 2. ROM 3. PROM 4. EPROM Random access memory (RAM):It is a primary memory which is also of two types i.e. Static RAM and Dynamic RAM. Read only memory (ROM): Special type of random access memory called as read only memory, is non volatile memory. Data stored on ROM is permanent and cannot be altered by the programmer. ROM is mainly used to store programs and data which do not change and are frequently used. ROM chip of the computer stores a set of instructions that are needed to make the computer system ready for use when its power is switched on. There are two types of ROM i.e. PROM and EPROM. Programmable read only memory ( PROM): It is a type of ROM on which data can be written only once . Once the chip has been programmed the recorded information cannot be changed. PROM is also known as non volatile storage. Erasable programmable read only memory (EPROM): In this type of ROM it is possible to erase the information stored in the chip and can be reprogrammed to store new information, this type of memory is called EPROM. EPROM are of two types i.e. UVPROM and EEPROM. 1. UVPROM: Information stored in the chip can be erased by exposing the chip for some time to ultraviolet light.
  • 7. 7 2. EEPROM: The information stored in the chip can be erased by using high electric voltage. Secondary Memory has been discussed under section 3.3 Check your progress (2) Say whether true or false:- 1. Main memory also called primary memory. 2. RAM is random accept memory. 3. Information stored on EEPROM erased by high electric voltage. 1.4 Input Output Device An I/O device( an input/output device) is a hardware device that provides the means of communication between the computer and outer world. They are also known as peripheral devices because they surround the CPU and the memory of the computer system. Input devices are used to enter the data from outside world to primary storage and output devices give results from primary storage to users. 1.4.1 Input Device An input device is a hardware device that sends data to the computer. Without any input device, a computer would only be a processing device and not allow users to interact with it. In other words, an input device is an electromechanical device that accepts data from outside world and translates them into a form the computer can interpret. Input devices are broadly classified into following categories.  Keyboard  Point-and-draw device  Data scanning device  Digitizer  Electronic card-based device  Voice recognition device  Vision based device  Offline data entry device 1.4.1.1 Keyboard The keyboard is the most commonly used input device today that allows data entry into a computer by pressing a set of keys. Keyboard can be classified into two types  General purpose keyboard  Special purpose keyboard
  • 8. 8 General purpose keyboard General purpose keyboard is a standard keyboard that is most commonly used as an input device. It has the set of typewriter-like keys that enables you to enter data into a computer. Computer keyboards are similar to electric-typewriter keyboards but contain additional keys. The keys on computer keyboards are often classified as follows:  alphanumeric keys -- letters and numbers  punctuation keys -- comma, period, semicolon, and so on.  special keys -- function keys, control keys, arrow keys, Caps Lock key, and so on. The standard layout of letters, numbers, and punctuation is known as a QWERTY keyboard because the first six keys on the top row of letters spell QWERTY. The QWERTY keyboard was designed in the 1800s for mechanical typewriters and was actually designed to slow typists down to avoid jamming the keys. Another keyboard design, which has letters positioned for speed typing, is the Dvorak keyboard. There is no standard computer keyboard, although many manufacturers imitate the keyboards of PCs. There are actually three different PC keyboards: the original PC keyboard, with 84 keys; the AT keyboard, also with 84 keys; and the enhanced keyboard, with 101 keys. The three differ somewhat in the placement of function keys, the Control key, the Return key, and the Shift keys. In addition to these keys, keyboards contain the following keys: Page Up, Page Down, Home, End, Insert, Pause, Num Lock, Scroll Lock, Break, Caps Lock, Print Screen. Special purpose keyboard This type of keyboard is specially designed and used for specific type of applications, so it is called a special purpose keyboard. It makes possible data entry at a faster rate and enables rapid interaction with computer system. It has only some special functional keys. For example terminals used in supermarket, ATM etc. 1.4.1.2 Point-and-draw device The GUI provides users a screen full of graphics icons or menus and allows them to make a rapid selection from displayed icons or menus to give instruction to computer. Such user interface computer requires an input device that can be used to rapidly point to and select a particular graphic icon or menu item from the multiple options displayed on the screen. Mouse, joystick, trackball, light pen, touch screen are some examples of point-and-draw devices.
  • 9. 9 Mouse A mouse is a hardware input device that was invented by Douglas Engel Bart in 1963. The mouse allows an individual to control a pointer in a graphical user interface (GUI). Utilizing a mouse, a user has the ability to perform various functions such as opening a program or file and does not require the user to memorize commands, like those used in a text-based command-line environment such as MS-DOS. The mouse was originally referred to as an X-Y Position Indicator for a display system. Xerox later applied the name mouse to its revolutionary Alto computer system in 1973. Today, a pointing device is found on virtually every computer. Trackball A trackball is an input device that looks like an upside-down mouse. The on-screen pointer is moved by the trackball with a thumb or finger. A trackball requires less arm and wrist motion than a regular mouse takes and therefore is often less stressful for the user to use. Joystick The joystick is an input device that looks similar to a control device you would find on an arcade game at your local arcades. A joystick allows an individual to easily move an object in a game such as navigating a plane in a flight simulator Light pen A light pen is an input device that utilizes a light-sensitive detector to select objects on a display screen. A light pen is similar to a mouse, except that with a light pen you can move the pointer and select objects on the display screen by directly pointing to the objects with the pen. Touch screen A touch screen is a computer display screen that is also an input device. The screens are sensitive to pressure; a user interacts with the computer by touching pictures or words on the screen. 1.4.1.3Data scanning devices Data scanning devices are input devices that enable direct data entry into a computer system from source documents thus eliminating the need to key-in text data into the computer. Due to reduced human effort in data entry, they improve data accuracy and also increase the timeliness of the information processed. They however demand high quality of input documents. Some data scanning devices are also capable of recognizing marks or characters. 1. Image Scanner
  • 10. 10 It is an input device that translates paper documents into an electronic format for storage in a computer. Electronic format of a scanned image is its bitmap representation. Stored images can be altered or manipulated with image-processing softwares. Common Types of Image Scanners  Flat - bed Scanner  Hand - held Scanner Flat - bed Scanner It looks like a photocopy machine. It has a box with a glass plate on the top & a lid. The document to be scanned is placed on the glass plate. A light source below the glass plate moves from one line to another & scans all the lines within few seconds. Hand – held Scanner It contains LEDs & can be held in hand. To scan, it is dragged slowly over the document from one end to another. It has to be dragged very slowly & steadily. It is used only when high accuracy is not needed. It is cheaper than a flatbed scanner. It is used when volume of documents to be scanned is low. Other scanners include: sheetfed scanner, which is a scanner that scans paper fed into it, and a card scanner, which is a small scanner capable of scanning business cards. 2. OCR – Optical Character Recognition  It is a scanner with character recognition software.  It uses OCR software that converts the bit map images of characters to ASCII codes.  It enables word processing of input text and also requires less space for storing the document.  OCR software is extremely complex because it is difficult to make a computer recognize an unlimited number of fonts  Two standard OCR fonts are OCR-A (American standard) and OCR-B (European standard) 3. OMR – Optical Mark Reader
  • 11. 11  It is a scanner capable of recognizing a pre-specified type of mark by a pencil or pen  It is very useful for grading tests with objective type questions, or for any input data that is of a choice or selection nature. 4. Bar Code Reader  It is a scanner used for reading (decoding) bar-coded data .  Bar codes represent alphanumeric data by a combination of adjacent vertical lines (bars) by varying their width and the spacing between them.  Scanner uses laser-beam to stroke across pattern of bar code. Different patterns of bars reflect the beam in different ways sensed by a light- sensitive detector.  Universal Product Code (UPC) is the most widely known bar coding system.  Barcode Printer is a hardware device capable of printing out adhesive barcodes that can be attached to a product. This helps identify the product or a company keep to track of its inventory. 5. MICR – Magnetic Ink Character Recognition  MICR is used by banking industry for faster processing of large volume of cheques.  Bank’s identification code (name, branch, etc.), account number and cheque number are pre-printed (encoded)using characters from a special character set on all cheques.  Special ink is used that contains magnetizable particles of iron oxide  MICR reader-sorter reads data on cheques and sorts them for distribution to other banks or for further processing. 1.4.1.4 Digitizer  It is an input device used for converting (digitizing) pictures, maps and drawings into digital form for storage in computers.  Commonly used in the area of Computer Aided Design (CAD) by architects and engineers to design cars, buildings medical devices, robots, mechanical parts, etc.  Used in the area of Geographical Information System(GIS) for digitizing maps available in paper form. 1.4.1.5 Electronic Card Reader  Electronic cards are small plastic cards having encoded data appropriate for the application for which they are used.  Electronic-card reader is used to read data encoded on an electronic card and transfer it to the computer for further processing.  Used together as a means of direct data entry into a computer system.
  • 12. 12  Used by banks for use in automatic teller machines(ATMs) and by organizations for controlling access of employees to physically secured areas. 1.4.1.6 Voice Recognition Devices Input devices that allow a person to input data to a computer system by speaking to it are called voice recognition devices. Today’s speech recognition systems are limited to accepting few words within a relatively small domain and can be used to enter only limited kinds and quantities of data. Uses of Speech Recognition  For inputting data to a computer system by a person in situations where his/her hands are busy.  For data input by dictation.  For authentication of a user by a computer system based on voice input.  For limited use of computers by individuals with physical disabilities. 1.4.1.7 Vision - Input Systems  Allow computer to accept input just by seeing an object.  Input data is normally an object’s shape and features in the form of an image. Digital camera A digital camera stores the pictures or video it takes in electronic format instead of to a film. There are several features that make digital cameras a popular choice when compared to film cameras. First, the feature often enjoyed the most is the LCD display on the digital camera. This display allows users to view photos or video after the picture or video has been taken, which means if you take a picture and do not like the results, you can delete it; or if you do like the picture, you can easily show it to other people. Another nice feature with digital cameras is the ability to take dozens, sometimes hundreds of different pictures. Digital cameras have become the camera solution for most users today as the quality of picture they take has greatly improved and as the price has decreased. 1.4.1.8 Myc Sometimes abbreviated as mic, a microphone is a hardware peripheral originally invented by Emile Berliner in 1877 that allows computer users to input audio into their computers. Check your progress (3) Fill in the blanks:-
  • 13. 13 1. Flat panel display is ………………….device. 2. Com stands for…………………… 3. To print engineering design application………………is used. 4. …………………converts text information into spoken sentence. 1.4.2 Output Devices An output device is an electrometrical device that accepts data from a computer and translates it into human understandable form and displays the result. It is also known as a peripheral device. The output devices are broadly classified into the following categories :  Monitor  Printer  Plotter  Computer output microfilm  Screen image projector  Voice response system 1.4.2.1 Monitor Monitor is also called a video display terminal (VDT) or video display unit (VDU). In its most common usage, monitor refers only to devices that contain no electronic equipment other than what is essentially needed to display and adjust the characteristics of an image. Like most TVs, the computer monitor has a CRT (Cathode Ray Tube) that is found inside the computer monitor. The CRT is the main component and most expensive part in the computer monitor. Flat-panel display Thin screen displays found with all portable computers are becoming the new standard with desktop computers. Instead of utilizing the cathode-ray tube technology, flat-panel displays use Liquid-crystal display (LCD) technology or other alternative making them much lighter and thinner when compared with a traditional monitor 1.4.2.2 Printer A printer is n external hardware device that is responsible for taking computer data and generating a hard copy of that data. Printers are one of the most used peripherals on computers and are commonly used to print text, images, or photos. Printers are of the following types:  Dot Matrix printer  Inkjet printer  Laser printer
  • 14. 14  Thermal printer  LED printer Dot-matrix printer It is a type of printer that produces characters and illustrations by striking pins against an ink ribbon to print closely spaced dots in the appropriate shape. Dot-matrix printers are relatively expensive and do not produce high-quality output. However, they can print to multi-page forms (that is, carbon copies), something laser and ink-jet printers cannot do. Dot-matrix printers vary in two important characteristics: speed: Given in characters per second (cps), the speed can vary from about 50 to over 500 cps. Most dot-matrix printers offer different speeds depending on the quality of print desired. print quality: Determined by the number of pins (the mechanisms that print the dots), it can vary from 9 to 24. The best dot-matrix printers (24 pins) can produce near letter-quality type, although you can still see a difference if you look closely. Inkjet printer The most popular printer for home computer users that prints by spraying streams of quick-drying ink on paper. The ink is stored in disposable ink cartridges, often a separate cartridge is used for each of the major colors. These colors are usually Black, Red/Magenta, Green/Cyan, and Yellow (CYMK). Although inkjet printers themselves are often relatively inexpensive, the ink cartridges used in the printers can increase the overall cost of the printer. Laser printer First developed at Xerox PARC by Gary Starkweather and released in 1971, a laser printer is a printer that utilizes laser technology to print images on the paper. Laser printers are often used in corporate, school, and other environments that require print jobs to be completed quickly and in large quantities. Thermal printer 1. A thermal impact printer or electro thermal printer is a printer that uses heated pins to "burn" images onto heat-sensitive paper. These printers are commonly used in calculators and fax machines; and although they are inexpensive and print relatively fast, they produce low resolution print jobs. 2. A thermal printer, thermal transfer printer, or thermal wax-transfer printer is a high quality printer invented by Jack Kilby that commonly utilizes a thermal wax ribbon that melts a colored wax onto the paper creating near photo-realistic images.
  • 15. 15 LED Printer Short for light emitting diode printer, LED printers were developed by Casio and are printers capable of printing at the same or close to the same quality as most laser printers. LED printers work much like laser printers but utilize a LED panel that recreates the image on a negatively charged drum. The areas where the light hits the drum become less charged, which attracts the toner. The printer then transfers the toner from the drum to the paper and applies intense heat to fuse the toner to the paper. 1.4.2.3 Plotters It is a device that draws pictures on paper based on commands from a computer. Plotters differ from printers in that they draw lines using a pen. As a result, they can produce continuous lines, whereas printers can only simulate lines by printing a closely spaced series of dots. Multicolor plotters use different-colored pens to draw different colors. In general, plotters are considerably more expensive than printers. They are used in engineering applications where precision is mandatory. There are two types of plotters: drum plotter and flatbed plotter. 1.4.2.4 Computer Output Microfilm COM (Computer Output Microfilm) is a process for copying data from electronic media on computers onto microfilm. COM can be produced as microfiche or as 16mm-roll microfilm. A high-speed recorder transfers machine-readable digital data onto human-readable microfilm using laser technology and a processor, which develops the microfilm after it is exposed to the light source. The recorder can operate off-line as a stand-alone device, or on-line connected to a local or wide-area network. A COM recorder usually has a duplicator connected to it that can create as many copies as needed. A sorter separates the duplicate fiche cards into bins. 1.4.2.5 Screen image projector A digital projector, also called a digital projection display system, is a specialized computer display that projects an enlarged image on a movie screen. Such devices are commonly used in presentations. The term digital projector is sometimes used for a program that facilitates the viewing of three-dimensional (3D), interactive, full-motion audio-visual files on a personal computer. Versions are available for both IBM-compatible and Macintosh computers, and can be downloaded from the Internet. They can be used as plug-ins for popular browsers for viewing animated Web-page content. For optimum performance on the
  • 16. 16 Internet, a broadband connection should be used because of the high-speed, interactive nature of the content, and because the transmitted files are often large There are two main types of digital projection display systems. The older, less expensive type employs three transparent liquid-crystal-display ( LCD ) panels, one for each of the primary colors (red, green, and blue). The light transmittivity of each pixel varies depending on the image data received from the computer. The light from a lamp is directed through the LCD panels, collimated using a lens, and projected onto a screen. The overall construction of the device is similar to that of a slide projector, where the "slide" consists of the three LCD panels placed close together near the focal point of the projection lens. Advantages of LCD technology include efficiency, ease of brightness and contrast adjustment, and high image resolution. A newer, more expensive scheme is known as Digital Light Processing (DLP), a proprietary technology developed by Texas Instruments. In a DLP display, tiny mirrors are used instead of transparent panels. Each mirror represents one pixel. The light, rather than passing through the panel, is reflected from it. The mirrors move back and forth, varying the amount of light that reaches the projection lens from each pixel. Color is obtained by passing the light from the lamp through a rotating wheel with red, green, and blue filters. This subjects the mirrors to light at each of the primary colors in a rapid rotating sequence. The result is a color-modulated image that the human eye sees as natural color. Advantages of DLP technology include light weight, high contrast, and lack of pixelation. 1.4.2.6 Voice response system A voice recognition system allows user to talk with the computer. It has an audio response device that produce audio output, audio response device is basically of two type one is Voice Reproduction System and other is Speech Synthesizer. Voice Reproduction System It produces audio output by selecting appropriate audio output from a set of prerecorded audio responses. Speech Synthesizer A speech synthesizer converts text information into spoken sentences. To produce speech, these devices combine basic sound units called phonemes. From a given text information, sequence of words are combined into phonemes, amplified, and output through the speaker attached to the system. Check your progress (4) Fill in the blanks:- 1. ………………device is used for converting picture, maps and drawing in digital form. 2. Data code in form of small lines is known as ……………
  • 17. 17 3. ………………..are capable of recognize a pre specified type of mark made by pencil or pen. 1.5 Storage devices A storage device is a hardware device capable of storing information. There are two storage devices used in computers: a primary storage device such as computer RAM and a secondary storage device such as a computer hard disk drive. Secondary storage device Alternatively referred to as external memory and auxiliary storage, secondary storage is a storage medium that holds information until it is deleted or overwritten regardless of the computer being on or off. For example, a floppy disk drive and hard disk drive are both good examples of secondary storage devices. There are three different types of storage on a computer. Although primary storage is accessed much faster than secondary storage because of the price and size limitations, secondary storage is used with today's computers to store all programs and personal data. 1.5.1 Magnetic tape Tapes for computers are similar to tapes used to store music. It is a coated strip of plastic on which data is magnetically encoded Storing data on tapes is considerably cheaper than storing data on disks. Tapes also have large storage capacities, ranging from a few hundred kilobytes to several gigabytes. Accessing data on tapes, however, is much slower than accessing data on disks. Tapes are sequential-access media, which means that to get to a particular point on the tape, the tape must go through all the preceding points. In contrast, disks are random-access media because a disk drive can access any point at random without passing through intervening points. Because tapes are so slow, they are generally used only for long-term storage and backup. Data to be used regularly is almost always kept on a disk. Tapes are also used for transporting large amounts of data. Tapes come in a variety of sizes and formats. Tapes are sometimes called streamers or streaming tapes. 1.5.2 Hard Disk A magnetic disk is a device on which you can store computer data. The term hard is used to distinguish it from a soft, or floppy, disk. Hard disks hold more data and are faster than floppy disks. A hard disk, for example, can store anywhere from 10 to more than 100 gigabytes, whereas most floppies have a maximum storage capacity of 1.4 megabytes. A single hard disk usually consists of several platters. Each platter requires two read/write heads, one for each side. All the read/write heads are attached to a single access arm so that they cannot move independently. Each platter has the same number of tracks, and a track location that cuts across all platters is called a cylinder. For
  • 18. 18 example, a typical 84 megabyte hard disk for a PC might have two platters (four sides) and 1,053 cylinders. In general, hard disks are less portable than floppies, although it is possible to buy removable hard disks. 1.5.3 Floppy A floppy is a soft magnetic disk. It is called a floppy because it flops if it is waved.. Unlike most hard disks, floppy disks (often called floppies or diskettes) are portable, because you can remove them from a disk drive. Disk drives for floppy disks are called floppy drives. Floppy disks are slower to access than hard disks and have less storage capacity, but they are much less expensive. And most importantly, they are portable. Floppies come in three basic sizes: 8 ½”, 5 ¼” and 3 ½”. 1.5.4 CD-ROM Pronounced see-dee-rom. Short for Compact Disc-Read-Only Memory, a type of optical disk capable of storing large amounts of data -- up to 1GB, although the most common size is 650MB (megabytes). A single CD-ROM has the storage capacity of 700 floppy disks, enough memory to store about 300,000 text pages. CD-ROMs are stamped by the vendor, and once stamped, they cannot be erased and filled with new data. To read a CD, you need a CD-ROM player. All CD-ROMs conform to a standard size and format, so you can load any type of CD-ROM into any CD-ROM player. In addition, CD-ROM players are capable of playing audio CDs, which share the same technology. CD-ROMs are particularly well-suited to information that requires large storage capacity. This includes large software applications that support color, graphics, sound, and especially video. 1.5.5 VCD VCD stands for 'Video Compact Disc' and basically it is a CD that contains moving pictures and sound. A VCD has the capacity to hold up to 74/80 minutes on 650MB/700MB CDs respectively of full-motion video along with quality stereo sound. VCDs use a compression standard called MPEG to store the video and audio. A VCD can be played on almost all standalone DVD Players and of course on all computers with a DVD-ROM or CD-ROM drive with the help of software based decoder / player. It is also possible to use menus and chapters, similar to DVDs, on a VCD and also simple photo album/slide shows with background audio. The quality of a very good VCD is about the same as a VHS tape based movie but VCD is usually a bit more blurry. VCD was introduced in 1993 by JVC, Philips, SONY and Matsushita .Video data is demanding in terms of storage capacity; it requires approximately 5 MB of storage
  • 19. 19 per second of video, which would translate to about two minutes of video on a 680 MB CD. In order to store video information on a CD in a practical fashion, the data must be compressed for storage and then decompressed for replay in real time. 1.5.6 Zip drive A zip drive is a high-capacity floppy disk drive developed by Omega Corporation. Zip disks are slightly larger than conventional floppy disks, and about twice as thick. They can hold 100 or 250 MB of data. Because they're relatively inexpensive and durable, they have become a popular media for backing up hard disks and for transporting large files. 1.5.7 DVD DVD stands for Digital Versatile/Video Disc, DVD-R stands for DVD- Recordable and DVD-RW for DVD-Rewriteable. A recordable DVD stores up to 2 hours of very good quality DVD-Video, including several audio tracks in formats like stereo, Dolby Digital or DTS and also advanced menu systems, subtitles and still pictures that can be played by many standalone DVD players and most computer DVD-ROMs. If you choose to lower the video quality it is possible to store several hours video on a recordable DVD using low bit rates and low resolution. It is also possible to have upto 4.37 GB ordinary data or mix DVD-Video and data on a recordable DVD that can be played by most computer DVD-ROMs. There are many competing DVD Recording standards, DVD-R / DVD-RW and DVD+R / DVD+RW have pretty similar features and are compatible with many standalone DVD Players and most DVD-ROMs while DVD-RAM has less DVD Player and DVD-ROM compatibility but better recording features. DVD-R and DVD-RW DVD-R was the first DVD recording format released that was compatible with standalone DVD Players.DVD-R is a non-rewriteable format and it is compatible with about 93% of all DVD Players and most DVD-ROMs. DVD-RW is a rewriteable format and it is compatible with about 80% of all DVD Players and most DVD- ROMs. DVD-R and DVD-RW supports single side 4.37 GiB* DVDs(called DVD-5) and double sided 8.75 GB* DVDs(called DVD-10).These formats are supported by DVD Forum.
  • 20. 20 DVD+R and DVD+RW DVD+R is a non-rewritable format and it is compatible with about 89% of all DVD Players and most DVD-ROMs.DVD+RW is a rewritable format and is compatible with about 79% of all DVD Players and most DVD-ROMs.DVD+R and DVD+RW supports single side 4.37 GiB* DVDs(called DVD-5) and double side 8.75 computer GB* DVDs(called DVD-10).These formats are supported by the DVD+RW Alliance. DVD+R DL DVD+R DL or called DVD+R9 is a Dual Layer writeable DVD+R. The dual layered discs can hold 7.95 GiB* (called DVD-9) and dual layered with double sides 15.9* GiB (called dvd-18). DVD-R DL DVD-R DL or called DVD-R9 is a Dual Layer writeable DVD-R. The dual layered discs can hold 7.95 GiB* (called DVD-9) and dual layered with double sides 15.9* GiB (called dvd-18). DVD-RAM DVD-RAM has the best recording features but it is not compatible with most DVD- ROM drives and DVD-Video players. Think more of it as a removable hard disk. DVD-RAM is usually used in some DVD Recorders. Check your progress (5) Say whether true or false:- 1. Magnetic tape is a storage device 2. Harddisk is less portable than floppy 3. Wc can store moving picture in VCD 1.6 Operating System The operating system forms an integral part of the computer system. It is essential to have knowledge about it, its components, goals, functions, importance etc. There are varieties of operating systems prevalent around the world and many new ones keep coming in. Each new developed operating system may have some new enhanced features and functionality but the basic features of all operating systems remain the same. With newer
  • 21. 21 version, efforts are made to enhance features of the operating system in order to provide a less troublesome session to the user. Here we will try to get a good understanding about the basic functions of the operating system and its importance. The most basic and simple definition of an operating system is “the software that controls the hardware.” It is a set of programs that make the computer hardware useable. It acts as an interface between the user and the hardware. It provides an environment within which other programs can do useful work. An operating system is a program designed to run other programs on a computer. A computer’s operating system is its most important program. It is considered the backbone of a computer, managing both software and hardware resources. Operating systems are responsible for everything from the control and allocation of memory to recognizing input from external devices and transmitting output to computer displays. They also manage files on computer hard drives and control peripherals, like printers and scanners. The operating system of a large computer system has even more work to do. Such operating systems monitor different programs and users, making sure everything runs smoothly, without interference, despite the fact that numerous devices and programs are used simultaneously. An operating system also has a vital role to play in security. Its job includes preventing unauthorized users from accessing the computer system. The abstract view of the components of a computer system shows the position of the operating system as below: USERS Operating system is an essential part of every computer system. The users are able to make efficient use of the basic computing resources available in the system with the help Application s/w Utility s/w, system program Operating system hardware
  • 22. 22 of the softwares especially the operating system. The operating system acts as an intermediary between the user of a computer system and the hardware. It controls and coordinates the use of hardware among the various application programs for the various users. It provides an environment so that the user can do his work in an efficient manner and also easily and conveniently Some examples of operating systems are UNIX, Mach, MS-DOS, MS-Windows, Windows/NT, Chicago, OS/2, MacOS, VMS, MVS, and VM. Operating systems are classified on the basis of their mode of interaction with the users as CUI (character user interface) and GUI (graphic user interface).  Under CUI, user has to type-in commands in proper syntax, for example DOS operating system.  GUI provides a picture oriented interface that provides menus and icons which can be selected by clicking on the icon with the help of a mouse. The user interacts with the operating systems through the user interface and is usually interested in the “look and feel” of the operating system, for example WINDOWS operating system. The most important components of the user interface are the command interpreter, the file system, on-line help, and application integration. Operating systems are also differentiated as being real time, multi-programmed, multiprocessing, multitasking, multithreading, networked, distributed, client- server, multiuser, time shared, clustered etc.  A multiuser operating system enables multiple users to run programs simultaneously. This type of operating system may be used for just a few people or hundreds of them. In fact, there are some operating systems that are used to allow thousands of people to run programs at the same time.  A multiprocessing operating system allows a program to run on more than one central processing unit (CPU) at a time. This can come in very handy in some work environments, at schools, and even for some home-computing situations. Multitasking operating systems work a little differently; they make it possible to run more than one program at a time. Multithreading operating systems are even more different, allowing varied parts of one program to be used simultaneously.
  • 23. 23  Real-time operating systems are designed to allow computers to process and respond to input instantly. Usually, general-purpose operating systems, such as disk operating system (DOS), are not considered real time, as they may require seconds or minutes to respond to input. Real-time operating systems are typically used when computers must react to the consistent input of information without delay. For example, real-time operating systems may be used in navigation, manufacturing units for controlling the operation of machines. Operating systems generally have following three major goals:  To hide details of hardware from the user through abstraction.  To allocate resources to processes.  Provide a pleasant and effective user interface Operating system components: Even though, not all systems have the same structure, many modern operating systems support the following system components: process management, primary memory management, file management, i/o system management, secondary storage management, security management and networking issues. Operating system functions: Some of the operating system functions are listed as below:  implementing the user interface,  sharing hardware among users,  allowing users to share data among themselves,  preventing users from interfering with one another,  scheduling resources among users,  facilitating input/output,  recovering from errors,  accounting for resource usage,  facilitating parallel operations,  organizing data for secure and rapid access, and  handling network communications
  • 24. 24 Prevalent operating systems: As already mentioned above, some of the commonly known operating systems are UNIX, Linux, Mach, MS-DOS, MS-Windows, Windows/NT, OS/2, MacOS etc. Some of the basic key features of these operating systems are given below for study, knowledge and comparison.  DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if we include the partially DOS-based Microsoft Windows versions 95, 98 and Millennium Edition. DOS is a single-user, single-task operating system with basic kernel functions that are non-re-entrant: only one program at a time can use them. There is an exception with Terminate and Stay Resident (TSR) programs, and some TSRs can allow multitasking. The DOS kernel provides various functions for programs, like displaying characters on-screen, reading a character from the keyboard, accessing disk files and more.  Microsoft Windows is a series of software operating systems and graphical user interfaces produced by the Microsoft Company. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces (GUIs). Microsoft Windows came to dominate the world's personal computer market, overtaking MacOS, which had been introduced previously. As of October 2009, Windows had approximately 91% of the market share of the client operating systems for usage on the Internet. The NT family of Windows systems was fashioned and marketed for higher reliability business use. Windows 7 is the latest release of Microsoft Windows, in the series of operating systems produced by Microsoft for use on personal computers, including home and business desktops, laptops, net books, tablet PCs, and media center PCs. Windows 7 was released on July 22- 2009, three years after the release of its predecessor, Windows Vista. The most recent client version of Windows is Windows 7; the most recent server version is Windows Server 2008 R2; the most recent mobile OS version is Windows Mobile 6.5. Windows 8, the successor to Windows 7, is currently in development.
  • 25. 25  The UNIX Operating System is available on machines with a wide range of computing power, from microcomputers to mainframes, and on different manufacture's machines. No other operating system can make this claim. The reasons of popularity and success of UNIX are explained below : Portability: The system is written in high-level language making it easier to read, understand, change and, therefore move to other machines. The code can be changed and compiled on a new machine. Customers can choose from a wide variety of hardware vendors without being locked in with a particular vendor. Machine-independence: The system hides the machine architecture from the user, making it easier to write applications that can run on micros, minis and mainframes. Multi-User Operations: UNIX is a multi-user system designed to support a group of users simultaneously. The system allows for the sharing of processing power and peripheral resources, while at the same time it provides excellent security features. Hierarchical File System: UNIX uses a hierarchal file structure to store information. This structure has the maximum flexibility in grouping information in a way that reflects its natural state. It allows for easy maintenance and efficient implementation. UNIX shell: UNIX has a simple user interface called the shell that has the power to provide the services that the user wants. It protects the user from having to know the intricate hardware details. Pipes and Filters: UNIX has facilities called Pipes and Filters which permit the user to create complex programs.  Linux is the operating system that is now used on a majority of web servers. Linux is an open operating system. This means the source code is freely available. Anyone distributing machine executable versions of this code should also be able to provide the source code. Also any changes to the source code should be available under the same licensing conditions. Linux is mainly developed by volunteers all over the world. Linux runs on widely differing hardware platforms ranging from small embedded systems over commodity personal computers to huge clusters for processor intensive jobs like scientific calculations or 3D rendering. The reasons of popularity and success of LINUX are explained below : Linux source code is freely distributed.
  • 26. 26 It has the best technical support available. It has no vendor lock-in. It runs on a wide range of hardware. It is exceptionally stable. It has the tools and applications you need. It interoperates with many other types of computer systems. It has a low total cost of ownership. Check your progress (6) Say whether true or false:- 1. Operating system is the backbone of computer system. 2. Multiuser OS allows a program to run on more than one CPU simaltanously. 3. Unix is single user OS. 1.7 Computer Languages A language which is acceptable to the computer system is called as computer language or programming language. computer languages are used to communicate with computers. Computer languages can be divided into two groups:  high-level languages  low-level languages. High-level languages High-level languages are designed to be easier to use, more abstract, and more portable than low-level languages. Syntactically correct programs in some languages are then compiled to low-level language and executed by the computer. Most modern software is written in a high-level language, compiled into object code, and then translated into machine instructions. By comparison, a high-level programming language isolates the execution semantics of a computer architecture from the specification of the program, which simplifies development. Programs written in high-level languages are translated into assembly language or machine language by a compiler. Assembly language programs are translated into machine language by a program called an assembler.
  • 27. 27 Every CPU has its own unique machine language. Programs must be rewritten or recompiled, therefore, to run on different types of computer. Low level languages A low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture. Generally this refers to either machine code or assembly language. The word "low" refers to the small or nonexistent amount of abstraction between the language and machine language; because of this, low-level languages are sometimes described as being "close to the hardware." Low-level languages can be converted to machine code without using a compiler or interpreter, and the resulting code runs directly on the processor. A program written in a low-level language can be made to run very fast, and with a very small memory footprint; an equivalent program in a high-level language will be more heavyweight. Low-level languages are simple, but are considered difficult to use, due to the numerous technical details which must be remembered. Example of Low-level programming languages are assembly language & machine language. Assembly language A programming language that is once removed from a computer's machine language. Machine languages consist entirely of numbers and are almost impossible for humans to read and write. Assembly languages have the same structure and set of commands as machine languages, but they enable a programmer to use names instead of numbers. Machine language Machine languages are the only languages understood by computers. While easily understood by computers, machine languages are almost impossible for humans to use because they consist entirely of numbers. Programmers, therefore, use either a high- level programming language or an assembly language. An assembly language contains the same instructions as a machine language, but the instructions and variables have names instead of being just numbers. Check your progress (7) Say whether true or false:- 1. Machine language and assembly language are low level language. 2. Machine language understand by computer easily. 1.8 Data processing
  • 28. 28 Computer data processing is any process that a computer program does to enter data and summarize, analyze or otherwise convert data into usable information. The process may be automated and run on a computer. It involves recording, analysing, sorting, summarising, calculating, disseminating and storing data. Because data are most useful when well-presented and actually informative, data-processing systems are often referred to as information systems. Data-processing systems typically manipulate raw data into information, and likewise information systems typically take raw data as input to produce information as output. Data processing may or may not be distinguished from data conversion, when the process is merely to convert data to another format, and does not involve any data manipulation. Processing Basically, data are nothing but facts (organized or unorganized) which can be converted into other forms to make it useful, clear and pratically used. This process of converting facts to information is called Processing. Practically all naturally occurring processes can be viewed as examples of data processing systems where "observable" information in the form of pressure, light, etc. are converted by human observers into electrical signals in the nervous system as the senses we recognize as touch, sound, and vision. Even the interaction of non-living systems may be viewed in this way as rudimentary information processing systems. Elements of data processing In order to be processed by a computer, data needs first be converted into a machine readable format. Once data are in digital format, various procedures can be applied on the data to get useful information. Data processing may involve various processes, including:  Data summarization  Data aggregation  Data validation  Data tabulation  Statistical analysis Check your progress (8) Say whether true or false:- 1. Process of converting text in information is called data processing. 2. Manipulation of data is done during processing. 3. Data validation is process of data processing.
  • 29. 29 1.9 Programming Programming is the process of writing a sequence of instructions to be excuted by a computer to solve a problem. It is also considered as the act of writing computer programs. Computer programs are set of instructions that tell a computer to perform certain operations. The instructions in programs are logically sequenced and assembled through the act of programming. Computer programming has many facets: It is like engineering because computer programs must be carefully designed to be reliable and inexpensive to maintain. It is an art because good programs require that the programmer use the intuition and a personal sense of style. It is a literary effort because programs must be understood by computers, and this requires mastery of a programming language. Programmers are people who write programs and use different programming language to communicate instructions to the computer. 1.9.1 Method of Problem Solving A computer is only a problem-solving tool. It is one of the many different tools engineers use in solving problems. A general method of problem solving may be described by the following steps: 1. Recognize and understand the problem. 2. Accumulate facts. 3. Select appropriate theory. 4. Make necessary assumptions. 5. Solve the problem. 6. Verify results. Performing step 5 i.e. solve the problem may involve a computer. Given below are five steps that are followed in using a computer as a problem-solving tool: 1. Develop an Algorithm and a Flowchart. 2. Write the program in a computer language. (i.e. Fortran, C) 3. Enter the program into the computer. 4. Test and debug the program. 5. Run the program, input data, and get the results from the computer. 1.9.2 Algorithm The programmer begins the programming process by analyzing the problem, breaking it into manageable pieces, and developing a general solution for each piece called an algorithm. An Algorithm is a detailed sequence of simple steps that are needed to solve a problem. Algorithm is the set of instructions written in plain English, for solving a problem or sub-problem in a finite amount of time using a finite amount of
  • 30. 30 data. An algorithm may be a verbal or written description of a logical sequence of actions applied to objects. Suppose a programmer needs an algorithm to determine an employee's weekly wages. The following algorithm reflects what would be done by hand: 1. Look up the employee's pay rate. 2. Determine the hours worked during the week. 3. If the number of hours worked is less than or equal to 40, multiply the hours by the pay rate to calculate regular wages. 4. If the number of hours worked is greater than 40, multiply 40 by the pay rate to calculate regular wages, and then multiply the difference between the hours worked and 40 by 1 1/2 times the pay rate to calculate overtime wages. 5. Add the regular wages to the overtime wages (if any) to determine total wages 1.9.3 Flowchart A Flowchart is a graphical representation of an algorithm. There are many basic symbols available to depict the various actions performed in algorithm writing. Of the many symbols available, these 6 basic symbols are used the most: Start/Stop Input/Output
  • 31. 31 Connector (connect one part of the flowchart to another) Process, Instruction Document Preparation (may be used with "do loops" ) Decision
  • 32. 32 Terminator Check your progress (9) Say whether True Or False: 1. Program is a set of instructions. 2. Graphic representation of program is called Algorithm. 3. Rectangle symbol used for start in flowchart. Check your progress ANSWER KEY ANSWER 1 1. Input, output, processing. 2.Input unit. 3. Memory 4.ALU ANSWER 2 1. True. 2. False. 3. True ANSWER 3 1. Output. 2. Computer output microfilm. 3.Plotter 4.Speech synthesizer. ANSWER 4 1. Digitizer. 2. Bar code. 3.OCR. ANSWER 5
  • 33. 33 1. True. 2. True. 3. True. ANSWER 6 1. True. 2. False. 3.True. ANSWER 7 1. True. 2. True ANSWER 8 1. False. 2. False. 3. True ANSWER 9 1. True. 2. False. 3. False
  • 34. 34 Unit II : Computer Programming in Fortan /C / Basic Structure :- 2.0 Introduction 2.1 Objectives 2.2 Constants, Variables and Data types 2.2.1 C Tokens 2.2.2 Keywords and Identifiers 2.2.3 Constants 2.2.4 Variable 2.2.5 Data types 2.2.6 C Instructions 2.2.7 Declaration of Variables 2.2.8 Where variables are declared 2.2.3 Basic Structure of C Program 2.3.1 The first C Program 2.4 Operators and Expressions 2.4.1 Arithmetic Operator 2.4.2 Relational Operator 2.4.3 Logical Operator 2.4.4 Assignment Operator 2.4.5 Increment and decrement Operator
  • 35. 35 2.4.6 Conditional Operator 2.4.7 Bitwise Operator 2.4.8 Special Operator 2.4.9 Precedence of Operator 2.5 Console I/O Functions 2.5.1 Formatted console I/O Functions 2.5.2 Unformatted console I/O Functions 2.6 Decision making and branching 2.7 The Loop Control Structure 2.7.1 The for Loop 2.7.2 The while loop 2.7.3 The do-while loop 2.7.4 The Break Statement 2.7.5 The continue Statement 2.8 The Case Control Structure 2.8.1 The Switch Statement 2.8.2 The Goto Statement 2.9 Array 2.10 Functions 2.11 Let Us Sum up 2.12 Check your Progress : The Key
  • 36. 36
  • 37. 37 2.0 Introduction :- A language is a means of communication. We use a natural language such as English to communicate our ideas and emotions to others. Similarly, a computer language is a means of communication used to communicate between people and the computer. With the help of a computer language, a programmer tells a computer what he/she wants it to do. In Other words ''A language that is acceptable to a computer system is called a Computer language or programming language, and the process of writing instructions in such a language for an already planned program is called programming or coding. C is a programming language developed at AT & T's Bell Laboratories of USA is 1972. It was designed and written by a Man Dennis Ritchie. C Seems so popular is because it is reliable, simple and easy to use. Programs written in C are efficient and fast. This is due to the variety of data types and powerful operators. Several standard functions are available which can be used for developing programs C is highly portable. The C character Set consists of alphabets (A,B,C ---- Z, a,b,______z, digits (0-9), Special Symbol. ( ~, (, !, @, # etc.) 2.1 Objectives :- The main aim of this unit is to study C programming language, and its application in the field of Chemistry to solve various Problems. Steps in learning C : Alphabets Digits Special Symbol Constants Variables Keywords Instruction Program
  • 38. 38 After going through this unit you should be able to develop small computer codes (Program) involving simple formulae in chemistry such as vander waals equation, Evaluation of lattice energy, sum of n number etc. Implementing is C language :- 2.2 Constants, Variables and Keywords :- The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. A constant is a Quantity that doesn't change. This quantity can be stored at a locations in the memory of the computer. A variable can be considered as a name given to the location is memory where this constant is stored. Naturally the contents of the variables can change. For example in the equation. 3 x + y = 20 Since 3 and 20 cannot change, they are called constants, whereas the quantities x and y can vary or change hence are called variables. 2.2.1 C Tokens :- In a C Program the Smallest individual units are known as C tokens. C has six types of tokens as shown in Fig. 2.1 Chemical equation or formulae Implying Using C varibles , keywords and constants (Declartion) Transforming required equation as 'C' Statements Executing the 'C' Statements as sequence of Program C Tokens Keywords Eg. Float Identifiers Constants Strings Eg OperatorE Special
  • 39. 39 2.2.2 Keywords and Identifiers :- Keywords :- Keywords are the words whose meaning has already been explained to the C compiler. The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. The keywords are also called 'Reserved words' There are only 32 keywords available in C. Following is the list of keywords in C. Identifies :- Identifiers are names that are given to various program elements such as variables, functions and array. These are user defined names and consist of a sequence of letters and digits, in auto double int struct break else long Switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if slatic while
  • 40. 40 any order, except that the first character must be a letter. Both uppercase and lowercase letters are permitted, although lowercase letters are commonly Used. The Underscore character is also permitted in identifiers. It is usually used as a link between two words in long identifiers. Ex - The following names are valid identifiers. x y12 sun1 names area Table 2.2.3 Constants :- Constants in C refer to fixed values that do not change during the execution of a program. Constant are also called literals. Constants Numeric Constants Character Constants Integer Real Single Character String Constant Constants Constants Constants Integer Constants :- An integer constant is an integer valued number. Thus it consists of a sequence of digits. Rules for constructing Integer Constants :- 1. An integer constant must have at least one digit. 2. It must not have a decimal point.
  • 41. 41 3. It could be either positive or negative. 4. If no sign precedes an integer constants it is assumed to be positive. 5. No commas or blanks are allowed within an integer constant. 6. The allowable range for integer constants is - 32768 to + 32767. Ex : 426 + 782 -8000 -7605 Real Constants :- Real constants are often called floating point constants the real constants could be written in two forms, Fractional form and Exponential form. Rules for Constructing Real constants :- Following rules must be observed while constructing real constants expressed in fractional form : 1. A real constants must have at least one digit. 2. It must have a decimal point. 3. It could be either positive or negative. 4. Default sign is positive. 5. No commas or blanks are allowed within a real constants. Ex : + 325.34 426.0 - 32.76 - 48.5792
  • 42. 42 The exponential form of representation of real constants is usually used if the value of the constant is either too small or too large. It however doesn't restrict us in any way from using exponential form of representation for other real constants. In exponential form of representation, the real constant is represented in two parts. The part appearing before 'e' is called mantissa, whereas the part following 'e' is called exponent. Following rules must be observed while construction of real constants in exponential form : 1. The mantissa part and the exponential part should be separated by a letter e. 2. The mantissa part may have a positive or negative sign. 3. Default sign of mantissa part is positive. 4. The exponent must have at least one digit which must be a positive or negative integer, Default sign is positive. 5. Range of real constants expressed in exponential form is - 3.4 e 38 to + 3.4 e 38. Ex : + 3.2e - 5 4. 1 e 8 - 0.2e + 3 - 3.2. e - 5 Character constant :- A single character constant (or simply character constant) contains a single character enclosed within a pair of single quote marks. Ex :- '5', 'x', ' ' Note that the character constant '5' is not the same as the number 5. The last constant is a blank space. Rules for constructing Character constants :-
  • 43. 43 1. A character constant is either a single alphabet, a single digit or a single special symbol enclosed within single inverted commas. Both the inverted commas should point to the left. For example 'A' is a valid character constant whereas ‘A’ is not. 2. The maximum length of a character constant can be one character. Ex: 'A' 'I' '5' '=' String Constants :- A string constant is a sequence of characters enclosed in double quotes. The characters may be letters, numbers, special characters and blank space. Examples are : ''Hello'', ''1987'', ''Well done'' Remember that a character constant (eg. 'x') is not equivalent to the single character string constant (eg ''x'') further a single character string constants does not have an equivalent integer value while a character constant has on integer value. Backslash Character Constants :- C Supports some special backslash character constants that are used in output function. for example the symbol 'n'' stands for newline character. A list of such backslash character constants is given in following table. Note that each one of them represents one character, although they consists of two characters. These characters combinations are known as Escape sequences. Table Backslash Character constants Constants Meaning 'a' Audible alert (bell) 'b' backspace 'f' from feed 'n' new line 'r' carriage return
  • 44. 44 'v' Vertical tab '' ' Single Quote ''' ' Double Quote '?' Question Mark '' Backslash 'o' null 2.2.4 Variables :- A quantity which may vary during program execution is called a variable. A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values of different times during execution. A variable name can be chosen by the programmer is a meaningful way so as to reflect its function or nature in the program. Some examples of such name are :- Average Height Total Counter Class_2 Rules for Constructing variables Names :- 1. A variable name is any combination of 1 to 8 alphabets, digits or underscore. some compilers allow variable name whose length could be upto 40 characters. Still, it would be safer to stick to the rule of 8 characters. 2. The first character in the variable name must be an alphabet. Some systems permit underscore as the first character. 3. No commas or blanks are allowed within a variable name. 4. No Special Symbol other than an underscore (eg. gross_sa) can be used in a variable name.
  • 45. 45 5. Keyword cannot be used as a variable name. This rule means we cannot give a variable a reserved name such as int, if. 6. The compiler treats uppercase and lowercase letters as different, although both may be used in constructing variable names. Therefore the variable names SUM, Sum and sum are regarded as the Separate variables in C. Usually however, Variable names in C are entirely in lowercase. Some examples of valid variable names are :- John Value T_raise Delhi X l ph_value Mark Sum1 Distance Invalid examples include : 123 (area) 25 cm Further examples of variable names and their correctness are given in following table 1.1 Table 1.1 Examples of Variable Names Variable Name Valid ? Remark 1) First_tag Valid - 2) char Not Valid char is a keyword 3) Price$ Not Valid Dollar Sign is illegal
  • 46. 46 4) Group one Not Valid Blank Space is not permitted 5) averagenumber Valid First Eight Characters are significant 6) int_ type Valid Keyword may be part of a name 2.2.5 Data Types :- Data types are the way to identify the type of data and associated operations of Handling it when variables are declared of a particulars data type ; then the variable becomes the place where the data is stored and data types is the type of value (data)stored by the variable.A good programmer language supports the programmer by giving. Such data types in which a control on a range of values and storage space is given to use. Finally we can say data types determine the three things - Memory limit - Values Limit - Operations Limit Data can be classified into many types such as character, integer, real etc. Since the data to be deal with are of many types, a programming language must provide different data types. In C language, data types can be classified in so many ways but here we are classifying the data types into three main categories : 1. Fundamental 2. Built in derived data type. 3. User defined derived data type. C Data Types Fudament al Data types Built in derived data types User defined derived Data types
  • 47. 47 Character Structure Integer Union Float Array Enum Double Pointer Typedef Void Generally in C four main data types are, used which may be represented differently within the computer memory. The basic data types are :- Data type Description Memory consumed 1. int integer Quantity 2 byte 2. char Single Character 1 byte 3. float real number 4 bytes 4. double real number with 8 bytes more precision Data types its format string and their Ranges Data type Format String (Conversion Character Range int % d -32768 to 32767 char % c -128 to 127 float % f - 3.4e 38 to 3.4e38
  • 48. 48 double % lf -1.7e 308 to 1.7e308 2.2.6 C Instructions :- Now that we have seen the different types of constants, variables and keywords the next logical step is to learn how they are combined to form instructions. There are basically four types of instructions in C : 1. Type declaration instruction 2. Input/Output instruction 3. Arithmetic Instruction 4. Control Instruction The purpose of each of these instructions is given below :- 1. Type declaration Instruction :- To declare the type of variable used in a C program. 2. Input/Output Instruction :- To perform the function of supplying input data to a program and obtaining the output results from it. 3. Arithmetic instruction :- To perform arithmetic operations between constants and variables. 4. Control instructions :- To control the sequence of execution of various statements in a C program. 2.2.7 Declaration of Variables :- After designing suitable variable names, we must declare them to the complier. Declaration does two things : 1. It tells the complier what the variable name is. 2. It specifies what types of data the variable will hold. The declaration of variables must be done before they are used in the program.
  • 49. 49 Type declaration :- A variable can be used to store a value of any data type. That is, the name has nothing to do with its type. The syntax for declaring a variable is as follows : Data type V1, V2 - Vn, V1, V2, ---Vn are the names of variables. Variable are separated by commas. A declaration statement must end with a semicolon, For example, valid declarations are : int count ; int number, total ; double ratio ; char ch ; int, double, and char are the keywords to represent integer type, real type and character type data values respectively. 2.2.8 Where variables Are declared :- Variables will be declared in three basic places : inside functions, in the definition of function parameters and Outside of all functions. These are local variable, formal parameters and global variables. Local Variables : Variable that are declared inside a function are called local variables. Local Variables exist only while the block of code in which they are declared is executing. That is, a local variable is created upon entry into its block and destroyed upon exit. The most common code block in which local variables are declared is the functions. Formal Parameters :- If a function is to use arguments, it must declare variables that will accept the valves of the arguments. These variables are called the formal parameters of the functions. They behave like any other local variables inside the function.
  • 50. 50 Check your progress 1 Notes : i) Write your answer in the space given below. ii) Compare your answer with those given at the end of the unit. Fill in the Blanks. a) A character variable can at a time store____________. b) A C Variable cannot start with___________and__________. c) The escape sequence character___________causes the cursor to move to the next line on the screen. d) Every program statement in a C program must end with a__________. Global Variables :- Unlike local variables, global variables are known throughout the program and may be used by any piece of code. Also, they will hold their value throughout the program's execution. You Create global variables by declaring them outside of any function, Any expression may access. then, regardless of what block of code that expression is in. Basic Structure of C Program :- Documentation Section Link Section Definition Section Global Declaration Section main ( ) Function Section { Declaration Part
  • 51. 51 The Documentation : Section consists of a set comment lines giving the name of the program, the author and other details, Which the programmer would like to use later. The Link section provides instruction to the complier to link functions from the system library. The Definition Section defines all symbolic constants. Global Declaration Section :- There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all the functions. This section also declares all the user defined functions. Every C Program must have one main ( ) function section. This section contains two parts, declaration part and executable part. The declaration part declares all the variables used in the executable part. There is at least one statement in the executable part. These two parts must appear between opening and the closing braces. The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function section is the logical end of the program. All statements in the declaration and executable parts end with a Semicolon. Function 1 Function 2 ' Function N
  • 52. 52 The Subprogram Section contains all the user defined functions that are called in the main ( ) function. User defined functions are generally placed immediately after the main ( ) function, although they may appear is any order. All sections, except the main () function section may be absent when they are not required. 2.3.1 The First C Program :- Each instruction is a C Program is written as a Separate statement. Therefore a complete C program is written as a separate statement. Therefore a complete C Program will comprise of a series of statements. These statements must appear in the same order in which we wish them to be executed ; unless of course the logic of the problem demands a deliberate 'jump' or transfer of control to a statement which is out of sequence. However big a program, the following rules are applicable to all C Statements : 1. Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable, constant or keyword. 2. Usually all statements are entered in Small case letters. 3. C has no specific rules for the position at which a statements is to be written. That's why it is often called a Free - Form Language. 4. Any C statements always ends with a ; (Semicolon). Let us now write down a simple C program to Calculate simple interest. / * Calculation of Simple Interest * / main ( ) { int p, n ; float r, si ; P = 1000 ; n = 3 ; r = 8.5 ;
  • 53. 53 si = (P * r * n) / 100 ; printf (''Simple interest = %f'', si) ; } This program when executed will produce the following output. Now a few useful tips about the program. - Comment about the program should be enclosed within /* * /. For example the first statement in our program are comments. - Any number of comments can be given at any place in the program. - Comment cannot be nested. For example /*Cal of SI/*Author san date 11/11/11 */*/. - A Comment can be split over more than one line, as in, /* This is a jazzy comment */ Although a lot of comments are probably not necessary in this program, it is usually the case that programmers tend too many. Comments should be used at any place where there is a possibility of confusion. - Any C Program is nothing but a combination of functions. main ( ) is one such function. Empty parentheses after main are necessary and they are indicating that the function main has no arguments or parameters. (The concepts of parameters will be discussed in detail later when we discuss function). Simple Interest = 255.000000
  • 54. 54 The main ( ) is a special function used by the C system to tell the computer where the program starts. Every program must have exactly one main function, If we use more than one main function, the complier cannot tell which one marks the beginning of the program. - The set of statements belonging to a function are enclosed within a pair of braces. For example, main ( ) { Statements 1 ; Statement 2 ; Statement 3 ; } - Any variable used in the program must be declared before using it. For example. int p, n ; float r, si ; - Any C statements always ends with a ; (Semicolon) For example, float r, si ; r = 8.5 ; - In the statements Si = (P* r* n) / 100 ; * and / are the arithmetic operators. - printf ( ) is a predefined standard C function for printing output. Predefined complied means that it a function that has already been written and linked together with our program at the time of linking.
  • 55. 55 - printf ( ) is a function which is used to print on the screen the value contained is a variable. The general form of printf ( ) statement is printf (''<Format String'', <list of variables>) ; printf (''message'') ; Above two general form of printf can be merged. For Example, printf (''Simple interest = %f'', si) ; The output of printf ('' Principal = % d n Rate = % f'', P,r ) ; would look like Principal = 1000 Rate = 8.5 What is 'n' doing is the above printf statement ? It is called newline and it takes the cursor to the next line. Therefore, you get the output split over two lines. 'n' is one of the several escape sequences available in C. 2.4 Operator and Expressions :- An Operator is a symbol that perform specific mathematical or logical manipulations in program. Operators are used in Programs to manipulate data and variable. They usually form a part of the mathematical or logical expressions. C Operators can be classified into a number of categories. They include : 1. Arithmetic Operator 2. Relational Operator 3. Logical Operator 4. Assignment Operator 5. Increment and decrement operators
  • 56. 56 6. Conditional Operators 7. Bitwise Operators 8. Special Operators Operand :- An Operand is a constant value or Variable on which operator performs the operation. An Operator cannot perform any operation without operand. To perform on operation, an operator requires at least one operand. On the basis of operand used in the expression ; we can categories the operators in another way. - Unary Operator :- That operates on a single operand. - Binary Operator :- When operator requires at least two operands to perform its specific operation then is called Binary operator. - Ternary Operator :- When Operator requires at least three operands to perform its specific operation then it is called Ternary operator. 2.4.1 Arithmetic Operator :- Symbols that are used to perform or represent arithmetic operations are known as Arithmetic Operator some arithmetic operations and their operators are given in the following table. Operator Meaning + Addition or Unary Plus - Subtraction or Unary minus * Multiplication / Division % Modulo Division Integer division truncates any fractional part The modulo division operation produces the remainder of an integer division. Examples of use of arithmetic operators are :
  • 57. 57 a - b a + b a x b a / b Here a and b are operands. . The modulo division operator cannot be used on floating point data. Arithmetic Expression : is a combination of variables, constants and operators arranged as per the syntax of the language. 2.4.2 Relational Operators :- The operators proceed about the relationship between two operands are known as relational operators. There are the binary operators that compare the values of both operands aside itself. An expression such as a < b or 1 < 20 containing a relational operator is termed as a relational expression. The value of a relational expression is either one or zero. It is one if the specified relation is true and zero if the relation is false. For example 10 < 20 is true but 20 < 10 is false C Supports six relational operators These operators and their meaning are shown in table. Operator Meaning < is less than < = is less than or equal to > is greater than > = is greater than or equal to
  • 58. 58 = = is equal to ! = is not equal to A simple relational expression contains only one relational operator and takes the following form:- ae -1 relational operator ae - 2 ae - 1 and ae - 2 are arithmetic expression, which may be simple constants, variables or combination of them. Given below are some examples of simple relational expression end their values : 4.5 < = 10 True 4.5 < = 10 False -35 > = 0 False 10 < 7 + 5 True a + b = = c + d True only if the sum of values of a and b is equal to the sum of values of c and d. When arithmetic expressions are used on either side of a relational operator, the arithmetic expressions will be evaluated first and then the results compared. That is, arithmetic operators have a higher priority over relational operators. Relational expressions are used in decision statement such as if and while to decide the course of action of a running program. 2.4.3 Logical Operators :- To form the Complex relational expressions we use the logical operators && (And) and || (OR) they work as connectors for more than one expression to make comparison more precise. There are three types of logical operators. Symbol Name Meaning 1. & & Logical AND True when all conditions are true
  • 59. 59 2. || Logical OR True when one of them is true. 3. ! Logical Not Negation The logical operator && and || are used when we want to test more than one condition and make decisions. An example is : a > b && x = = 10 An expression of this kind, which combines two or more relational expressions, is termed as a logical expression or a compound relational expression. 2.4.4 Assignment Operator :- The operators are used to assigning a value of variable, constant or expression to a variable, known as Assignment Operators. The General form of the assignment operator is. Variable_name = expression ; Where an expression may be as simple as a single constant or as complex as you require. Ex : a = 5 ; An expression of the form variable = expression is called as assignment expression and when it is followed by the semicolon ( ; ) it is called as assignment statement. Compound Assignment Operators :- For compounding the expression compound assignment operators are Used C contains the following five compound assignment operators +=, - =, *=, /= and % = To see how they are used, consider the first operator +=, The assignment expression expression 1 + = expression 2 ; is equivalent to expression 1 = expression 1 + expression 2 ;
  • 60. 60 Example :- a + = 5 ; is equivalent to a = a + 5 ; and so on for all five operators. Usually expression 1 is an identifiers. 2.4.5 Increment and Decrement Operators :- C allow two very useful operator not generally found in other languages. These are the increment and decrement operators : ++ and --. The Operator ++ Order adds 1 to the operand, while -- Subtracts 1, Both are unary operators and takes the following form : ++ m ; or m ++ ; - - m ; or m --; Prefix Notation :- In prefix form operator Occurs before the operand. Postfix Notation :- In Postfix form operator occurs after the operand. While ++ m and m++ mean the same thing when they form statements independently, they behave differently when they are used in expressions on the right - hand side of an assignment statement. Consider the following :- m = 5 ; y = ++ m ; In this case, the value of y and m would be 6. Suppose, If we rewrite the above statements as m = 5 ; y = m + + ; then, the value of y would be 5 and m would be 6. A Prefix Operator first adds 1 to the operand and then the result is assigned to the variable on left. On the other hand, a postfix Operator first assigns the value to the variable on left and then increments the operand.
  • 61. 61 Rules for ++ and -- Operators :- 1. Increment and decrement operators are unary operators and they require variable as their operands. 2. When postfix ++ (or--) is used with a variable is an expression, the expression is evaluated first using the original value of the variable and then the variable is incremented (or decrement) by one. 3. When prefix ++ (or --) is used in an expression, the variable is incremented (or decrement) first and then the expression is evaluated using the new value of the variable. 4. The precedence and associatively of ++ and -- operators are the same as those of unary + and Unary -. 2.4.6 Conditional Operator :- A ternary operator pair ''? :'' is available in C to construct conditional expression of the form. exp 1 ? exp 2 : exp 3 Where exp1, exp2 and exp3 are expression The Operators ? : Works as follows :- exp1 is evaluated first. If it is nonzero (true) the exp2 is evaluated and becomes the valve of the expression, IF expl is False, exp3 is evaluated and its valve becomes the value of the expression. Not that only one of the expression (either exp2 or exp3) is evaluated. For example, consider the following statements a = 10 ; b = 15 ; x = (a > b) ? a : b ; 2.4.7 Bitwise Operators :- C has a die of supporting special operators known as bitwise operators for manipulation of data at bit level. These operators are used for testing the bits, or shifting them right or left. Bitwise operators may not be applied to float or double.
  • 62. 62 Table : Bitwise Operators Operator Meaning & Bitwise AND ! Bitwise OR ^ Bitwise Exclusive OR << Shift left >> Shift right 2.4.8 Special Operators :- C Supports Some Special operators of interest such as Comma Operator and Size of Operator. Comma Operators :-The Comma Operator can be used to link the related expression together. A comma linked list of expressions are evaluated left to right and the valve of right most expression is the value of right most expression is the value of the combined expression. For Example, the statement Value = (x = 10, y = 5, x + y) ; First assigns the value 10 to x, then assigns 5 to y, and finally assigns 15 (i.e. 10 + 5) to value. Since comma operator has the lowest precedence of all operators, the parentheses are necessary. The size of Operator :- The size of is a compile time operator and, when used with an operand, it returns the number of bytes the operand occupies. The operand may be a variable, a constant or a data type Qualifier. Examples : m = sizeof (Sum) ; n = sizeof (long int) ; k = sizeof (235.5) ;
  • 63. 63 The sizeof Operator is normally used to determine the lengths of arrays and structures when their sizes are not known to the programmer. It is also used to allocate memory space dynamically to variables during execution of a program. 2.4.9 Precedence of Operators :- The order or priority in which the operations are performed in an expression is called precedence. Hierarchy of Operations :- The priority of precedence in which the operations in an arithmetic statement are performed is called the hierarchy of operations. The hierarchy of commonly used operators is shown in following table : Priority Operators Description Ist / * % Division, multiplication, Modular division 2nd + - Addition, Subtraction 3rd = Assignment Now a few tips about usage of operators in general. a) In case of a tie between operations of same priority preference is given to the operator which occurs first. for example Z = a * b + c/d ; Here a * b will be performed before c/d even though * and / has same or equal priority, This is because * appears prior to the / operation. b) If there are more than one set of parentheses the operations within the innermost parentheses will be performed first, followed by the operations within the second innermost pair and so on. c) We must always remember to use pairs of parentheses. A careless imbalance of the right and left parentheses is a common error. Example :- Determine the hierarchy of operations and evaluate the following expression ; i = 2 * 3/4 + 4/4 + 8-2 + 5/8
  • 64. 64 Stepwise evaluation of this expression is shown below :- i = 2 * 3/4 + 4/4 + 8 - 2 + 5/8 i = 6/4 + 4/4 + 8 - 2 + 5/8 Operation : * i = 1 + 4/4 + 8 - 2 + 5/8 Operation : / i = 1 + 1 + 8 - 2 + 5/8 Operation : / i = 1 + 1 + 8 - 2 + 0 Operation : / i - 2 + 8 - 2 + 0 Operation : + i = 10 - 3 + 0 Operation : + i = 8 + 0 Operation : - i = 8 Operation : + Note that 6/4 gives 1 and not 1.5 This so happens because 6 and 4 both are integers and therefore would evaluate to only an integer constant. Similarly 5/8 evaluates to zero, since 5 and 8 are integer constants and hence must return an integer value. 2.5 Console I/O Functions :- Functions to receive input from keyboard and write output to VDU are known as console I/O Functions. This can be classified into two categories : Formatted Check your progress 2 Notes : i) Write your answer in the space given below. ii) Compare your answer with those given at the end of the unit. Determine the hierarchy of operations and evaluate the following expression : KK = 3/2 * 4 + 3/8 + 3
  • 65. 65 and Unformatted console I/O functions. The basic difference between them is that the formatted as per our requirements. For example, if values of average marks and percentage marks are to be displayed on the screen, the detail like where this output would appear on the screen, then the details like where this output would be present between the two values, the number of places after the decimal points etc. can be controlled using formatted functions. The functions available under each of these two categories are shown in figure 2.2. Fig 2.2 2.5.1 Formatted Console I/O Functions :- As can be seen from figure 2.2 the functions printf ( ) and scanf( ) fall under the category of formatted console I/O Functions. These functions allow us to supply the input in a fixed format and let us obtain the output in the specified form. printf Function :- The general form of Printf Statement is Console Input/Output Fnuctions Formatted Functions Type Input Output char scanf() printf( ) int scanf() printf( ) float scanf() printf( ) double scanf() printf() Unformatted Functions Type Input Output Char getch() putch( ) getche() putchar( ) getchar() String gets() puts()
  • 66. 66 printf (''Format String'', list of variables). or printf (''Control String'', arg1, ang2........argn) ; The format string (Control String) consists of three types of items :- 1. Characters that will be printed on the Screen as they appear. 2. Format Specifications that define the output format for display of each item. 3. Escape Sequence characters such asn,t andb. The Control String indicates how many arguments follow and what their types are. The arguments arg1, arg2...........argn are the variables whose values formatted and printed according to the specification of the control string. The arguments should match in number, order and type with the format specifications. Examples of printf () Statement are :- 1. printf (''Programing in C''); 2. printf ('' %d'', x) ; where x is a integer variable. 3. printf (''Sum = % f'', total) ; Where total is a float variables. 4. printf ('' n'') ; scanf () Functions :- The general form of Scanf ( ) Statements is as follows :- scanf (''format string'', list of addresses of variables) ; or scanf (''Control String'', ang1, ang2..........angn) ;
  • 67. 67 The Control String Specifies the field format in which the data is to be entered and the arguments arg1, arg2........................., argn, Specify the address of locations where the data is stored. control string and arguments are separated by Commas. Control string (also known as format string) contains field specifications, which direct the interpretation of input data. It may include : - Field (or format) specifications, consisting of the conversion character %, a data type character (or type specifies), and an optional number, specifying the field width. - Blanks, tabs or newlines. Blanks, tabs and newlines are ignored The data type character indicates the type of data that is to be assigned to the variable associated with the corresponding argument. The field width specifier is optional. For Example :- Scanf (''%d% f%c'', &ab, &b, &ch); where int ab ; float b ; char ch ; Note that we are sending addresses of variables (addresses are obtained by using & the address of operator) to scanf () function. This is necessary because the values received from keywords must be dropped into variables corresponding to these addresses. 2.5.2 Unformatted Console I/O Functions :- There are several standard library functions available under this category - those which can deal with a single character and those which can deal with a string of character. (i) getchar () Function :- Reading a single character can be done by using the function getchar. The general form of getchar () function is as follows :- Variable _ Name = getchar () ;
  • 68. 68 Variable name is a valid C name that has been declared as char type. When this statement is encountered, the computer waits until a key is pressed and then assigns this character as a value to getchar () function, since getchar() is used on the right hand side of an assignment statement, the character value of getchar ( ) is in turn assigned to the variable name on the left. For example char Name ; Name = getchar ( ); will assigns the character 'H' to the variable name when we press the key 'H' on the keyboard. (ii) putchar ( ) Function :- It is used for writing character one at a time to the Screen. The general form of putchar ( ) function is as follows. putchar (Variable Name) ; Where variable name is a type char variable containing a character. This statement displays the character contained in the variable name at the terminal (Screen). For example, the statements char answer = 14' ; putchar (answer) ; Will display the character 4 on the Screen. 2.6 Decision making and Branching :- A decision control instruction can be implemented in C using : (a) The if statement
  • 69. 69 (b) The if-else statement (c) The Conditional Operators These statements are popularly known as Decision making statements. Since these statement control the flow of execution, they are also known as control statements. (a) The if statement :- C uses the keyword if to implement the decision control instruction. The general form of if statement looks like this : if (test expression) { Statement - block ; } The statement block may be a single statement or a group of statements. If the test expression is true, the statement block will be executed ; otherwise the statement block will be skipped and the execution will jump to the next statement. Remember, when the condition is true both the statement block and the next statement are executed in sequence. (b) The if.....else statements :- The if-else statement is an extension of the simple if statement. The general form is. if (test expression) { True- block statements (s) } else
  • 70. 70 { False - Block Statement (s) } If the test expression is true, then the true block statements (s), immediately following the if statements are executed ; otherwise, the false - block statement (s) are executed. In either case, either true-block or false-block will be executed, not both. Example :- Write a program to find given number is even or ODD. main ( ) { int num ; printf (''Enter any Number'') ; scanf (''%d''', &num) ; if (num % 2 = = 0) { printf (''Even number''). } else { printf (''ODD Number'') ; } getch ( ) ;