Download ebooks file Programming for Problem Solving E Balagurusamy all chapters
Download ebooks file Programming for Problem Solving E Balagurusamy all chapters
com
https://ebookmass.com/product/programming-for-problem-
solving-e-balagurusamy/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmass.com/product/problem-solving-and-python-programming-
e-balagurusamy/
ebookmass.com
https://ebookmass.com/product/computer-programming-e-balagurusamy/
ebookmass.com
Programming in C E. Balagurusamy
https://ebookmass.com/product/programming-in-c-e-balagurusamy/
ebookmass.com
https://ebookmass.com/product/programming-in-ansi-c-6th-edition-e-
balagurusamy/
ebookmass.com
Programming and Problem Solving with Python Ashok Namdev
Kamthane
https://ebookmass.com/product/programming-and-problem-solving-with-
python-ashok-namdev-kamthane/
ebookmass.com
https://ebookmass.com/product/python-programming-using-problem-
solving-approach-1st-edition-reema-thareja/
ebookmass.com
https://ebookmass.com/product/introduction-to-programming-with-java-a-
problem-solving-approach-3rd-edition-john-dean/
ebookmass.com
https://ebookmass.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-4th-edition-stormy-attaway/
ebookmass.com
https://ebookmass.com/product/data-structures-e-balagurusamy/
ebookmass.com
PROGRAMMING
fOR
PRObleM SOlvING
Gujarat Technological University - 2018
About the Author
E Balagurusamy, is presently the Chairman of EBG Foundation, Coimbatore. In the past he has also held
the positions of member, Union Public Service Commission, New Delhi and Vice-Chancellor, Anna University,
Chennai. 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, 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.
A recipient of numerous honors and awards, he has been listed in the Directory of Who's Who of Intellectuals
and in the Directory of Distinguished Leaders in Education.
PROGRAMMING
fOR
PRObleM SOlvING
Gujarat Technological University - 2018
E Balagurusamy
Chairman
EBG Foundation
Coimbatore
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 The Composers, 260, C.A. Apartment, Paschim Vihar, New Delhi 110 063 and printed at
Cover Printer:
Cover Designer: APS Compugraphics
Cover Image Source: Shutterstock
Visit us at: www.mheducation.co.in
Write to us at: info.india@mheducation.com
CIN: U22200TN1970PTC111531
Toll Free Number: 1800 103 5875
Preface
P
rogramming for Problem Solving requires a deep understanding of C. C is a powerful, flexible, portable
and elegantly structured programming language. Since C combines the features of high-level language
with the elements of the assembler, it is suitable for both systems and applications programming. It
is undoubtedly the most widely used general-purpose language today in operating systems, and embedded
system development. Its influence is evident in almost all modern programming languages. Since its
standardization in 1989, C has undergone a series of changes and improvements in order to enhance the
usefulness of the language.
Acknowledgements
I owe special thanks to the entire team of McGraw Hill Education India.
A note of acknowledgement is due to the following reviewers for their valuable feedback.
This book is my sincere attempt to make a footprint on the immensely vast and infinite sands of knowledge.
I would request the readers to utilize this book to the maximum extent.
E Balagurusamy
Publisher’s Note
McGraw Hill Education (India) invites suggestions and comments from you, all of which can be sent to info.
india@mheducation.com (kindly mention the title and author name in the subject line).
Piracy-related issues may also be reported.
Contents
Translator Programs 58
Problem-Solving Techniques 59
Using the Computer 70
Learning Outcomes 70
Key Concepts 71
Review Questions 73
Discussion Questions 84
2. Fundamentals of C 87
Learning Objectives 87
History of C 87
Importance of C 89
Sample Program 1: Printing a Message 89
Sample Program 2: Adding Two Numbers 92
Sample Program 3: Interest Calculation 93
Sample Program 4: Use of Subroutines 95
Sample Program 5: Use of Math Functions 96
Basic Structure of C Programs 97
Programming Style 98
Executing a ‘C’ Program 99
UNIX System 99
MS-DOS System 102
Key Concepts 102
Always Remember 103
Review Questions 103
Debugging Exercises 105
Programming Exercises 105
5. Functions 220
Learning Objectives 220
Introduction 220
Need for User-Defined Functions 221
A Multi-Function Program 221
Elements of User-Defined Functions 224
x Contents
6. Pointers 273
Learning Objectives 273
Introduction 273
Understanding Pointers 274
Accessing the Address of a Variable 276
Declaring Pointer Variables 277
Initialization of Pointer Variables 278
Accessing a Variable Through its Pointer 279
Chain of Pointers 281
Pointer Expressions 282
Pointer Increments and Scale Factor 284
Pointers and Arrays 284
Pointers and Character Strings 288
Array of Pointers 290
Pointers as Function Arguments 291
Functions Returning Pointers 294
Contents xi
7. Structure 311
Learning Objectives 311
Introduction 311
Defining a Structure 312
Declaring Structure Variables 313
Accessing Structure Members 315
Structure Initialization 316
Copying and Comparing Structure Variables 318
Operations on Individual Members 320
Arrays of Structures 320
Arrays within Structures 323
Structures within Structures 324
Structures and Functions 326
Unions 329
Size of Structures 330
Bit Fields 330
Key Concepts 333
Always Remember 333
Brief Cases 334
Review Questions 338
Debugging Exercises 341
Programming Exercises 341
Introduction to computer and programming: Introduction, Basic block diagram and functions of various
components of computer, Concepts of Hardware and software, Types of software, Compiler and interpreter,
Concepts of Machine level, Assembly level and high level programming, Flowcharts and Algorithms
Fundamentals of C: Features of C language, structure of C Program, comments, header files, data types,
constants and variables, operators, expressions, evaluation of expressions, type conversion, precedence
and associativity, I/O functions
GO TO Chapter 2 Fundamentals of C
Control structure in C: Simple statements, Decision making statements, Looping statements, Nesting of
control structures, break and continue, goto statement
Array & String: Concepts of array, one and two dimensional arrays, declaration and initialization of arrays,
string, string storage, Built-in-string functions
Recursion: Recursion, as a different way of solving problems. Example programs, such as Finding
Factorial, Fibonacci series, Ackerman function etc. Quick sort or Merge sort.
Functions: Concepts of user defined functions, prototypes, definition of function, parameters, parameter
passing, calling a function, recursive function, Macros, Pre-processing
GO TO Chapter 5 Functions
Pointers: Basics of pointers, pointer to pointer, pointer and array, pointer to array, array to pointer, function
returning pointer
GO TO Chapter 6 Pointers
Structure: Basics of structure, structure members, accessing structure members, nested structures, array
of structures, structure and functions, structures and pointers
GO TO Chapter 7 Structure
introduction
A computer is an electronic machine that takes input from the user, processes the given input and generates
output in the form of useful information. A computer accepts input in different forms such as data, programs
and user reply. Data refer to the raw details that need to be processed to generate some useful information.
Programs refer to the set of instructions that can be executed by the computer in sequential or non-
sequential manner. User reply is the input provided by the user in response to a question asked by the
computer.
A computer includes various devices that function as an integrated system to perform several tasks
described above (Fig. 1.1). These devices are:
Central Processing Unit (CPU)
It is the processor of the computer that is responsible for controlling and executing instructions in the computer.
It is considered as the most significant component of the computer.
Discovering Diverse Content Through
Random Scribd Documents
CHAPITRE III
LE BILL DE L’INDE, 1783. — PITT RÈGNE MALGRÉ LE
PARLEMENT.
D’HASTINGS. — 1785-95.
(Lucan.)
Cet aimable Édouard, celui dont il s’agit, était un fils cadet des
ducs de Leinster. Il fut élevé en France par un Écossais qui avait
épousé sa mère, devenue veuve. On l’envoya en Amérique faire la
guerre contre la Fayette et les Français qu’il devait tant aimer. Là,
comme tant d’autres alors, il s’éprit de la vie sauvage. Dans un
voyage qu’il fit à travers les neiges du Canada, les Indiens, à leur
tour, furent si charmés de lui, de sa naïve et vaillante originalité,
qu’ils l’adoptèrent, le proclamèrent chef de la tribu de l’Ours. Pitt eût
voulu le gagner, l’employer ; il lui offrait le commandement de
l’expédition anglaise contre Cadix. Il mettait à cela une condition :
qu’il se ferait bon Anglais, quitterait l’opposition irlandaise. Il refusa ;
ce chemin à l’action, à la gloire, lui fut ainsi barré. D’autre part, sa
fortune n’était pas meilleure en amour. Comme cadet, il n’était pas
riche, et, à son retour d’Amérique, il avait eu l’insigne douleur de voir
sa fiancée qui en épousait un autre.
La France, la grande Révolution, le consolaient de tout. Il dîna
avec Fox dans la joie qu’apporta la nouvelle de Valmy et de la
retraite des Prussiens. Il ne tint pas à cette joie, passa en France et
logea à Paris, d’abord chez Thomas Payne, l’apôtre de la liberté des
deux mondes. Que ne fût-il resté chez cet ami austère ! Il aurait fait
comme son compatriote Tone, qui devint général en France ; il se fût
lancé dans les guerres de la liberté. Mais une affaire de cœur fut son
entrave. Aux réjouissances que l’on fit à Paris pour Jemmapes, le
jeune général Égalité, personnage très calculé, invita le citoyen Fitz-
Gerald et le fit dîner avec madame de Genlis et son élève, la
charmante Paméla (fille naturelle du duc d’Orléans). Le voilà pris. Il
aime et il épouse. Cela le brouille d’abord avec sa famille ; puis avec
l’Angleterre, qui le raye des rôles de son armée. Le voilà donc
Français ? Non pas. Son fatal mariage avec les Orléans empêche
notre gouvernement de l’employer.
Cependant la tempête soufflait en France et en Irlande. Fitz-
Gerald, condamné à une oisiveté solitaire, et désespéré d’être
heureux, avec sa Paméla, leur enfant, son jardin en fleurs, s’efforçait
d’ignorer et de ne pas prévoir. On frémit en lisant ses lettres et son
imprévoyance, en entendant la tourmente cruelle qui s’agite déjà
autour de cette idylle.
On dit que le cœur trop plein, au moment où Hoche préparait sa
grande expédition d’Irlande, il dit la chose non seulement à
Sheridan, l’ami du prince de Galles, mais inconsidérément à une
dame liée avec un ami de Pitt.
Cette parfaite nature, douce et chevaleresque, mais fort peu
révolutionnaire, n’avait pas la fixité de vues, la décision qui fait le
succès. Il appelait la Révolution, les Français, et en même temps il
craignait qu’ils ne réussissent trop et ne s’emparassent de l’Irlande,
que lui-même ne passât pour traître, ayant machiné la conquête de
sa patrie. Et cependant, il se disait : « L’Amérique a bien appelé les
Français ! »
Le prince régent pleura Fitz-Gerald, — comme le czar Paul et son
fils pleurèrent Kosciuszko, qu’ils visitaient dans sa prison. Mais ils
n’en firent pas plus pour la Pologne et pour l’Irlande.
Le mouvement avait commencé en Irlande par un très grand
spectacle d’amitié, de fraternité, tel qu’on en voit rarement sur la
terre. Les Irlandais protestants à Belfast réparaient la longue
injustice qu’avaient soufferte leurs frères catholiques, au point que
les catholiques qui portaient dans Dublin la pétition de Liberté furent
traînés en triomphe par les protestants. La Liberté effaçait tout, et la
fraternité semblait rester comme la religion de la terre. Belfast avait
célébré l’anniversaire de la Révolution française, en arborant quatre
pavillons : France, Irlande, Amérique, et Pologne. Le pavillon anglais
manquait ; à tort. Car l’Angleterre s’agitait elle-même. Le drapeau
irlandais du 1er bataillon national était toujours la harpe, mais
désormais elle était surmontée non plus de la couronne, mais du
bonnet de la liberté.
Cependant Pitt avait sacrifié vingt millions pour acheter le
parlement d’Irlande. Et ce qui valait mieux pour lui, le sang versé en
France, et en Irlande la crainte des propriétaires, agissait, et le
danger de donner l’élection aux catholiques, si ignorants, barbares.
Pitt s’était procuré l’alliance secrète du pape contre la France. Pie VI
lui écrivait cyniquement : « Nous n’avons plus que vous ! » Les
prêtres catholiques, craignant par-dessus tout la France,
excommunièrent quiconque se joindrait aux Français.
Hoche avait été un peu retardé ; il se défiait de son amiral
Villaret-Joyeuse, en demanda un autre, et, pour le surveiller, monta
sur le même vaisseau, lequel fut écarté par les tempêtes de
décembre et ne put aborder. Grouchy, son lieutenant, arriva seul
avec 1 800 hommes. Ce général, très brave, mais très
malencontreux, eut déjà là son Waterloo : il craignit une si grande
responsabilité, ne voulut pas agir sans Hoche ; Bouvet aussi, son
amiral, refusait d’aborder. Il y avait, dit-on, plusieurs centaines de
mille hommes en armes, mais fort désordonnés. Un Judas avait
organisé une machine perfide de police. On s’était arrangé pour que
des dragonnades, des cruautés de soldats fissent éclater
l’insurrection trop tôt. Belfast et tout le Nord s’en retirèrent [19] .
[19] L’un des directeurs, la Réveillère-Lepeaux, avait
en Irlande son gendre qui y habitait depuis plusieurs
années. Il aurait dû s’informer d’autant mieux des causes
du non-succès. Les royalistes firent manquer tout deux
fois. En décembre 96, nos officiers de marine ne voulaient
pas réussir. Hoche s’était mis sur une frégate, comme
jadis Suffren faisait en pareil cas, pour se porter partout
avec plus de rapidité. Malgré le mauvais temps, ils le
promenèrent un mois en mer et se refusèrent aux prières
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
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.
ebookmass.com