Computer Programming and Utilization, 4e 4th Edition E. Balagurusamy 2024 Scribd Download
Computer Programming and Utilization, 4e 4th Edition E. Balagurusamy 2024 Scribd Download
com
https://textbookfull.com/product/computer-programming-and-
utilization-4e-4th-edition-e-balagurusamy/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/programming-in-ansi-c-6th-edition-e-
balagurusamy/
textboxfull.com
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/
textboxfull.com
https://textbookfull.com/product/identity-in-
adolescence-4e-adolescence-and-society-4th-edition-laura-ferrer-
wreder/
textboxfull.com
Computer Vision and Image Analysis Digital Image
Processing and Analysis 4th Edition Scott E Umbaugh
https://textbookfull.com/product/computer-vision-and-image-analysis-
digital-image-processing-and-analysis-4th-edition-scott-e-umbaugh/
textboxfull.com
https://textbookfull.com/product/assistive-technologies-principles-
and-practice-4e-4th-edition-albert-m-cook-phd-pe/
textboxfull.com
https://textbookfull.com/product/first-aid-for-the-pediatrics-
clerkship-4e-true-pdf-4th-edition-latha-ganti/
textboxfull.com
https://textbookfull.com/product/disjunctive-programming-balas-e/
textboxfull.com
https://textbookfull.com/product/programming-php-4th-edition-peter-
macintyre/
textboxfull.com
COMPUTER PROGRAMMING
AND
UTILIZATION
Fourth Edition
CC: 2110003
(Common to all Engineering Branches)
About the Author
E Balagurusamy, former Vice Chancellor, Anna University, Chennai and Member, Union Public Service
Commission, New Delhi, is currently the Chairman of EBG Foundation, Coimbatore. He is a teacher,
trainer, and consultant in the fields of Information Technology and Management. He holds an ME (Hons)
in Electrical Engineering and PhD in Systems Engineering from the Indian Institute of Technology
(IIT) Roorkee. His areas of interest include Object-Oriented Software Engineering, E-Governance:
Technology Management, Business Process Re-engineering, and Total Quality Management.
A prolific writer, he has authored a large number of research papers and several books. His
best-selling books, among others include:
∑ Programming in ANSI C, 7/e
∑ Fundamentals of Computers
∑ Computing Fundamentals and C Programming
∑ Programming in Java, 5/e
∑ Programming in BASIC, 3/e
∑ Programming in C#, 3/e
∑ Numerical Methods
∑ Reliability Engineering
∑ Introduction to Computing and Problem Solving using Python, 1e
A recipient of numerous honors and awards, E Balagurusamy has been listed in the Directory of
Who's Who of Intellectuals and in the Directory of Distinguished Leaders in Education.
COMPUTER PROGRAMMING
AND
UTILIZATION
Fourth Edition
CC: 2110003
(Common to all Engineering Branches)
E Balagurusamy
Chairman
EBG Foundation
Coimbatore, Tamil Nadu
Copyright © 2018, 2017, 2015, 2014 by McGraw Hill Education (India) Private Limited.
No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise or stored in a database or retrieval system without the prior written permission of
the publishers. The program listings (if any) may be entered, stored and executed in a computer system, but they may not
be reproduced for publication.
This edition can be exported from India only by the publishers,
McGraw Hill Education (India) Private Limited.
Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed to be
reliable. However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or completeness of any
information published herein, and neither McGraw Hill Education (India) nor its authors shall be responsible for any errors,
omissions, or damages arising out of use of this information. This work is published with the understanding that McGraw
Hill Education (India) and its authors are supplying information but are not attempting to render engineering or other
professional services. If such services are required, the assistance of an appropriate professional should be sought.
Typeset at APS Compugraphics, 4G, PKT 2, Mayur Vihar Phase-III, Delhi 96, and printed at
Cover Printer:
Preface xiii
Roadmap to the Syllabus xvii
1. Introduction to Computer and Programming 1.1–1.30
1.1 Introduction 1.1
1.2 Basic Anatomy of a Computer System 1.2
1.3 Input Devices 1.3
1.4 Output Devices 1.5
1.5 Software 1.7
1.6 Hardware 1.9
1.7 Programming Languages 1.9
1.8 Translator Programs 1.12
1.9 Programming Environment 1.14
1.10 Introduction to the Design and Implementation of Correct,
Efficient and Maintainable Programs 1.14
1.11 Structured Programming 1.15
1.12 Problem Solving 1.15
1.13 Algorithms 1.15
1.14 Flowcharts 1.19
Just Remember 1.27
Review Questions 1.28
Multiple Choice Questions 1.29
Answers 1.30
2. Fundamentals of C 2.1–2.20
2.1 History of C 2.1
2.2 Features of C Level Language 2.2
2.3 Sample Program 1: Printing a Message 2.3
2.4 Sample Program 2: Displaying Your Name 2.6
2.5 Sample Program 3: Adding Two Numbers 2.6
2.6 Sample Program 4: Interest Calculation 2.8
2.7 Sample Program 5: Finding Ceil of a Number 2.10
2.8 Sample Program 6: Use of Math Functions 2.10
2.9 Basic Structure of C Programs 2.12
2.10 Programming Style 2.13
2.11 Executing a ‘C’ Program 2.13
Just Remember 2.15
vi Contents
The developments in digital electronics and related technologies during the last few decades have
ushered in the second Industrial Revolution, popularly referred to as the Information Revolution.
Computer technology plays an ever-increasing role in this new revolution. Application of computers is
all-pervasive in the life of every human today. A sound knowledge of how computers work and how they
process data and information has, therefore, become indispensable for anyone who seeks employment
not only in the area of IT but also in any other fields.
Rightly so, many institutions and universities in India have introduced a subject covering the
fundamentals of computers and programming in C and C++ at the undergraduate and diploma levels of
arts, science and engineering disciplines.
The fourth edition of the book Computer Programming and Utilization has been revised keeping
in mind the first year engineering students of Gujarat Technological University undergoing the course
Computer Programming and Utilization (2110003).
Salient Features
∑ Up-to-date and complete coverage of GTU syllabus
∑ Precise theory presented in lucid language
∑ Codes with comments provided throughout the book to illustrate the use of various features of
the language
∑ Excellent coverage of flowcharts and algorithms
∑ Supplementary information and notes that complement but stand apart from the text are
included in special boxes
∑ Just Remember given at the end of each chapter for quick recap of the concepts
∑ Application based programs are given in every chapter
∑ Solved question papers including summer 2016, winter 2016 and summer 2017
xiv Preface
∑ Rich pedagogy:
o 158 Multiple Choice Questions given at the end of every chapter to help test the
understanding of learner
o 729 Review Questions provide ample opportunities to test the conceptual understanding of
features
o 198 Programming Exercises and 44 Debugging Exercises stimulate interest to practice
programming applications
o 195 Figures and over 133 Examples serve as effective study aids
o 5 Practical Sets given at the end of the book
Chapter Organisation
The book has been divided into 15 chapters. Chapter 1 gives an overview of computers, their
development, characteristics and evolution. Next, the fundamentals of C are introduced in Chapter 2.
Chapter 3 explains data types in C. Operators and their hierarchy, and the concept of header files and
I/O operations are taken up in Chapters 4 and 5 respectively.
Control structures—decision making, branching and looping—are covered subsequently in
Chapters 6 and 7. Arrays in ANSI C are presented in Chapter 8. Chapter 9 deals with strings. Functions
and recursion forms the subject of discussion in Chapter 10, while pointers, structures and unions are
covered in Chapters 11 and 12 respectively.
The principles of dynamic memory allocation and linked lists are introduced in Chapter 13,
while Chapter 14 guides the reader on file management in C. Finally, the preprocessor is taken up in
Chapter 15.
The book provides numerous examples, illustrations and complete programs. The sample programs
are meant to be both simple and educational. Wherever necessary, pictorial descriptions of concepts are
included to improve clarity and facilitate better understanding. The book also presents the concept of
oriented approach and discusses briefly the important elements of object programming.
Acknowledgements
A special note of thanks to the following reviewers for their valuable feedback:
Hardik Molia Government Engineering College, Rajkot, Gujarat
Bintu Kadhiwala Sarvajanik College of Engineering and Technology, Surat, Gujarat
Archana Nayak GIDC Degree Engineering College, Abrama, Gujarat
Chintan Bhavsar G.H. Patel College of Engineering and Technology, Gujarat
Kajal S Patel Government Engineering College, Gandhinagar, Godhra, Gujarat
Preface xv
I would like to thank all those who provided me with valuable feedback and inputs during the preparation
of this book, and especially those at McGraw Hill Education, without whose help and cooperation, this
book would not have had a timely release. Special thanks are also due to all my teacher friends and students
for their encouragement. I hope everyone who desires to be a part of the next generation of computing
will find this book interesting and useful. Further suggestions for improvement will always be welcome.
— E Balagurusamy
Publisher's Note
Constructive suggestions and criticism always go a long way in enhancing any endeavour. We
request all readers to email us their valuable comments/views/feedback for the betterment of the
book at [email protected], mentioning the title and author name in the subject line.
Also, please feel free to report any piracy of the book spotted by you.
Roadmap to the Syllabus
Computer Programming and Utilization
GO TO
Chapter 1 Introduction to Computers and Programming
GO TO Chapter 2 Fundamentals of C
Chapter 3 Data Types in C
Chapter 4 Operations and their Hierarchy
Chapter 5 Input–Output Functions
GO TO
Chapter 6 Control Structures: Decision Making and Branching
Chapter 7 Control Structures: Decision Making and Looping
xviii Roadmap to the Syllabus
Arrays and Strings—Concepts of array; One and two-dimensional arrays; Declaration and
initialization of arrays; String; String storage; Built-in-string functions
GO TO
Chapter 8 Arrays
Chapter 9 Strings
Pointers—Basics of pointers; Pointer to pointer; Pointer and Array; Pointer to array; Array of
pointers; Functions returning a pointer
GO TO Chapter 11 Pointers
1.1 Introduction
The term computer is derived from the word compute. A computer is an electronic device that takes
data and instructions as an input from the user, processes data, and provides useful information known
as output. This cycle of operation of a computer is known as the input–process–output cycle and is
shown in Fig. 1.1. The electronic device is known as hardware and the set of instructions is known as
software.
INPUT OUTPUT
Data PROCESS Information
Instructions
The spurt of innovations and inventions in computer technology during the last few decades has led
to the development of a variety of computers. They are so versatile that they have become indispensable
to engineers, scientists, business executives, managers, administrators, accountants, teachers and
students. They have strengthened man’s powers in numerical computations and information processing.
Modern computers possess certain characteristics and abilities peculiar to them. They can:
(i) perform complex and repetitive calculations rapidly and accurately,
(ii) store large amounts of data and information for subsequent manipulations,
(iii) hold a program of a model which can be explored in many different ways,
(iv) compare items and make decisions,
(v) provide information to the user in many different forms,
(vi) automatically correct or modify the parameters of a system under control,
1.2 Computer Programming and Utilization
A computer system comprises of hardware and software components. Hardware refers to the physical
parts of the computer system and software is the set of instructions or programs that are necessary for
the functioning of a computer to perform certain tasks. Hardware includes the following components:
• Input devices — They are used for accepting the data on which the operations are to be
performed. The examples of input devices are keyboard, mouse and track ball.
• Processor — Also known as CPU, it is used to perform the calculations and information
processing on the data that is entered through the input device.
• Output devices — They are used for providing the output of a program that is obtained after
performing the operations specified in a program. The examples of output devices are monitor
and printer.
• Memory — It is used for storing the input data as well as the output of a program that is obtained
after performing the operations specified in a program. Memory can be primary memory as
well as secondary memory. Primary memory includes Random Access Memory (RAM) and
secondary memory includes hard disks and floppy disks.
Introduction to Computer and Programming 1.3
Software supports the functioning of a computer system internally and cannot be seen. It is
stored on secondary memory and can be an application software as well as system software. The
application software is used to perform a specific task according to requirements and the system software
is mandatory for running application software. The examples of application software include Excel and
MS Word and the examples of system software include operating system and networking system.
All the hardware components interact with each other as well as with the software. Similarly, the
different types of software interact with each other and with the hardware components. The interaction
between various hardware components is illustrated in Fig. 1.2.
Magnetic Magnetic
Tape Disk
Arithmetic
Unit
Control
Unit
CPU
Data and results flow
Control Instructions to units
Instructions to control unit
Input devices can be connected to the computer system using cables. The most commonly used input
devices among others are:
• Keyboard
• Mouse
• Scanner
1.4 Computer Programming and Utilization
1.3.1 Keyboard
A standard keyboard includes alphanumeric keys, function keys, modifier keys, cursor movement keys,
spacebar, escape key, numeric keypad, and some special keys, such as Page Up, Page Down, Home,
Insert, Delete and End. The alphanumeric keys include the number keys and the alphabet keys. The
function keys are the keys that help perform a specific task such as searching a file or refreshing a
Web page. The modifier keys such as Shift and Control keys modify the casing style of a character or
symbol. The cursor movement keys include up, down, left and right keys and are used to modify the
direction of the cursor on the screen. The spacebar key shifts the cursor to the right by one position. The
numeric keypad uses separate keypads for numbers and mathematical operators. A keyboard is shown in
Fig. 1.3.
Function Keys
(F1 to F12)
Escape Key
Special Keys
Numeric Keypad
Modifier Keys
1.3.2 Mouse
The mouse allows the user to select elements on the screen, such as tools, icons, and buttons, by pointing
and clicking them. We can also use a mouse to draw and paint on the screen of the computer system. The
mouse is also known as a pointing device because it helps
Wheel
change the position of the pointer or cursor on the screen.
Right Button
The mouse consists of two buttons, a wheel at the
Left Button
top and a ball at the bottom of the mouse. When the ball
moves, the cursor on the screen moves in the direction in
which the ball rotates. The left button of the mouse is used
to select an element and the right button, when clicked,
displays the special options such as open and explore and
Fig. 1.4 Mouse shortcut menus. The wheel is used to scroll down in a
document or a Web page. A mouse is shown in Fig. 1.4.
1.3.3 Scanner
A scanner is an input device that converts documents and images as the digitized images understandable
by the computer system. The digitized images can be produced as black and white images, gray images,
or colored images. In case of colored images, an image is considered as a collection of dots with each
dot representing a combination of red, green, and blue colors, varying in proportions. The proportions
Introduction to Computer and Programming 1.5
of red, green, and blue colors assigned to a dot are together called as
color description. The scanner uses the color description of the dots
to produce a digitized image. Fig. 1.5 shows a scanner.
There are the following types of scanners that can be used to
produce digitized images:
• Flatbed scanner — It contains a scanner head that moves across
a page from top to bottom to read the page and converts the
image or text available on the page in digital form. The flatbed
scanner is used to scan graphics, oversized documents, and
pages from books.
• Drum scanner — In this type of scanner, a fixed scanner head
Fig. 1.5 Scanner is used and the image to be scanned is moved across the head.
The drum scanners are used for scanning prepress materials.
• Slide scanner — It is a scanner that can scan photographic slides directly to produce files
understandable by the computer.
• Handheld scanner — It is a scanner that is moved by the end user across the page to be scanned.
This type of scanner is inexpensive and small in size.
The data, processed by the CPU, is made available to the end user by the output devices. The most
commonly used output devices are:
• Monitor
• Printer
• Speaker
• Plotter
1.4.1 Monitor
A monitor is the most commonly used output device that produces visual displays generated by the
computer. The monitor, also known as a screen, is connected as an external device using cables or
connected either as a part of the CPU case. The monitor connected using cables, is connected to the
video card placed on the expansion slot of the motherboard. The display device is used for visual
presentation of textual and graphical information.
The monitors can be classified as cathode ray tube (CRT) monitors or liquid crystal display (LCD)
monitors. The CRT monitors are large, occupy more space in the computer, whereas LCD monitors are
thin, light weighted, and occupy lesser space. Both the monitors are available as monochrome, gray
scale and color models. However, the quality of the visual display produced by the CRT is better than
that produced by the LCD.
The inner side of the screen of the CRT contains the red, green, and blue phosphors. When a beam
of electrons strike the screen, the beam strikes the red, green and blue phosphors on the screen and
irradiates it to produce the image. The process repeats itself for a change in the image, thus refreshing
the changing image. To change the color displayed by the monitor, the intensity of the beam striking the
screen is varied. If the rate at which the screen gets refreshed is large, then the screen starts flickering,
when the images are refreshed.
1.6 Computer Programming and Utilization
The LCD monitor is a thin display device that consists of a number of color or monochrome pixels
arrayed in front of a light source or reflector. LCD monitors consume a very small amount of electric
power.
A monitor can be characterized by its monitor size and resolution. The monitor size is the length of
the screen that is measured diagonally. The resolution of the screen is expressed as the number of picture
elements or pixels of the screen. The resolution of the monitor is also called the dot pitch. The monitor
with a higher resolution produces a clearer image.
1.4.2 Printer
The printer is an output device that transfers the text displayed on the screen, onto paper sheets that can
be used by the end user. The various types of printers used in the market are generally categorized as
dot matrix printers, inkjet printers, and laser printers. Dot matrix printers are commonly used in low
quality and high volume applications like invoice printing, cash registers, etc. However, inkjet printers
are slower than dot matrix printers and generate high quality photographic prints. Since laser printers
consist of microprocessor, ROM and RAM, they can produce high quality prints in quicker time without
being connected to a computer.
The printer is an output device that is used to produce a hard copy of the electronic text displayed on
the screen, in the form of paper sheets that can be used by the end user. The printer is an external device
that is connected to the computer system using cables. The computer needs to convert the document
that is to be printed to data that is understandable by the printer. The printer driver software or the print
driver software is used to convert a document to a form understandable by the computer. When the
computer components are upgraded, the upgraded printer driver software needs to be installed on the
computer.
The performance of a printer is measured in terms of dots per inch (DPI) and pages per minute
(PPM) produced by the printer. The greater the DPI parameter of a printer, the better is the quality of
the output generated by it. The higher PPM represents higher efficiency of the printer. Printers can be
classified based on the technology they use to print the text and images:
• Dot matrix printers — Dot matrix printers are impact printers that use perforated sheet to
print the text. The process to print a text involves striking a pin against a ribbon to produce its
impression on the paper. As the striking motion of the pins help in making carbon copies of a
text, dot matrix printers are used to produce multiple copies of a print out.
• Inkjet printers — Inkjet printers are slower than dot matrix printers and are used to generate
high quality photographic prints. Inkjet printers are not impact printers. The ink cartridges are
attached to the printer head that moves horizontally, from left to right. The print out is developed
as the ink of the cartridges is sprayed onto the paper. The ink in the inkjet is heated to create
a bubble. The bubble bursts out at high pressure, emitting a jet of the ink on the paper thus
producing images.
• Laser printers — The laser printer may or may not be connected to a computer, to generate an
output. These printers consist of a microprocessor, ROM and RAM, which can be used to store
the textual information. The printer uses a cylindrical drum, a toner and the laser beam. The toner
stores the ink that is used in generating the output. The fonts used for printing in a laser printer
are stored in the ROM or in the cartridges that are attached to the printer. The laser printers are
available as gray scale, black and white or color models. To print high quality pages that are
graphic intensive, laser printers use the PageMaker software.
Introduction to Computer and Programming 1.7
1.4.3 Speaker
The speaker is an electromechanical transducer that converts an electrical signal into sound. They are
attached to a computer as output devices, to provide audio output, such as warning sounds and Internet
audios. We can have built-in speakers or attached speakers in a computer to warn end users with error
audio messages and alerts. The audio drivers need to be installed in the computer to produce the audio
output. The sound card being used in the computer system decides the quality of audio that we listen
using music CDs or over the Internet. The computer speakers vary widely in terms of quality and price.
The sophisticated computer speakers may have a subwoofer unit, to enhance bass output.
1.4.4 Plotter
The plotter is another commonly used output device that is connected to a computer to print large
documents, such as engineering or constructional drawings. Plotters use multiple ink pens or inkjets
with color cartridges for printing. A computer transmits binary signals to all the print heads of the
plotter. Each binary signal contains the coordinates of where a print head needs to be positioned for
printing. Plotters are classified on the basis of their performance, as follows:
• Drum plotter — They are used to draw perfect circles and other graphic images. They use a
drawing arm to draw the image. The drum plotter moves the paper back and forth through a roller
and the drawing arm moves across the paper.
• Flat-bed plotter — A flat bed plotter has a flat drawing surface and the two drawing arms that
move across the paper sheet, drawing an image. The plotter has a low speed of printing and is
large in size.
• Inkjet plotter — Spray nozzles are used to generate images by spraying droplets of ink onto the
paper. However, the spray nozzles can get clogged and require regular cleaning, thus resulting in
a high maintenance cost.
• Electrostatic plotter — As compared to other plotters, an electrostatic plotter produces quality
print with highest speed. It uses charged electric wires and special dielectric paper for drawing.
The electric wires are supplied with high voltage that attracts the ink in the toner and fuses it with
the dielectric paper.
1.5 Software
In the field of computer science, software is defined as a computer program, which includes logical
instructions used for performing a particular task on a computer system using hardware components. The
following are the two major categories of software under which different types of computer programs
can be classified:
• System software
• Application software
Figure 1.6 shows the relationship among hardware, software, and user.
The figure shows a layered architecture, which represents different components of a computer such
as hardware, system software, application software, and user in a hierarchical manner.
1.8 Computer Programming and Utilization
Hardware
System software
Application software
User
1.6 Hardware
The physical devices that make up the computer are called Hardware. The hardware units are responsible
for entering, storing and processing the given data and then displaying the output to the users. The basic
hardware units of a general purpose computer are keyboard, mouse, memory, CPU, monitor and printer.
Among these hardware units, keyboard and mouse are used to input data into the computer, memory is
used to store the entered data, CPU is used to process the entered data and monitor and printer are used
to display the processed data to the users.
CPU is the main component inside the computer that is responsible for performing various operations
and also for managing the input and output devices. It includes two components for its functioning,
Arithmetic Logic Unit (ALU) and Control Unit (CU). ALU is used to perform the arithmetic operations
such as addition, subtraction, etc. and logic operations such as AND, OR, etc. on the data obtained from
the memory. CU is used to control the activities related to the input and output devices. It obtains the
instructions from the memory, decodes them and then, executes them so as to deliver output to the users.
The XNOR gate can be logically expressed as:
A≈ B
Table 1.1 shows the truth table of XNOR gate.
Table 1.1 Truth Table of XNOR Gate
The operations of a computer are controlled by a set of instructions (called a computer program). These
instructions are written to tell the computer:
1. What operation to perform
2. Where to locate data
3. How to present results
4. When to make certain decisions
The communication between two parties, whether they are machines or human beings, always needs
a common language or terminology. The language used in the communication of computer instructions
is known as the programming language. The computer has its own language and any communication
with the computer must be in its language or translated into this language.
Three levels of programming languages are available. They are:
1. machine languages (low level languages)
2. assembly (or symbolic) languages
3. procedure-oriented languages (high level languages)
1.10 Computer Programming and Utilization
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com