(Ebooks PDF) Download Programming For Problem Solving - GTU 2018 - Ebook PDF Full Chapters
(Ebooks PDF) Download Programming For Problem Solving - GTU 2018 - Ebook PDF Full Chapters
com
https://ebookluna.com/download/programming-for-problem-
solving-ebook-pdf/
OR CLICK HERE
DOWLOAD NOW
https://ebookluna.com/product/ebook-pdf-programming-problem-solving-
and-abstraction-with-c/
ebookluna.com
https://ebookluna.com/download/problem-solving-and-python-programming-
ebook-pdf/
ebookluna.com
https://ebookluna.com/download/programming-and-problem-solving-with-
python-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-java-an-introduction-to-
problem-solving-and-programming-7th-edition/
ebookluna.com
(eBook PDF) Java: An Introduction to Problem Solving and
Programming 8th Edition
https://ebookluna.com/product/ebook-pdf-java-an-introduction-to-
problem-solving-and-programming-8th-edition/
ebookluna.com
https://ebookluna.com/download/mathematics-1-gtu-2018-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-matlab-a-practical-
introduction-to-programming-and-problem-solving-4th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-introduction-to-programming-
with-java-a-problem-solving-approach-3rd-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-community-policing-
partnerships-for-problem-solving-8th-edition/
ebookluna.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: [email protected]
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.
[email protected] (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.
Other documents randomly have
different content
So Rago shouted very loudly. He shouted again and again.
The leader of the men heard the call.
“I hear someone calling,” he said. “Let us go into the forest and see
who it is.”
So all of the men went into the forest and soon came upon Rago
and Goni, who were sitting on the ground, with their mother and
baby sister.
“Did you call?” asked the leader.
“Yes,” answered their mother. “Will you take us with you?
“We should like to join your clan.”
“Yes,” said the leader, “we shall be glad to have you.”
“Shall we have someone to play with?” asked Rago.
“Yes, there are many boys and girls in our clan,” answered the
leader.
“You are very brave,” said Rago. “I watched you drive the huge
rhinoceros to the edge of the cliff.”
“I should like to be as brave as you are when I am a man.”
“We will teach you how to be brave,” said the leader.
“Come, let us start as it is getting late.”
So they all started off together.
Rago and Goni weren’t a bit afraid because they were with these
brave men.
“What is that?” asked Rago, pointing to the firebrand.
“This is a fire-torch,” said the leader; “when we carry these we need
not be afraid.
“Fire protects us from the wild beast.”
“And where do you get fire?” asked Rago.
“Not so very long ago we had a terrible storm in our forest. It
thundered and lightened.
“The lightning set fire to the trees in the forest.
“At first we Tree-dwellers thought that the fire was a terrible
monster. We were frightened and ran away from it.
“Then we learned that the fire would not harm us and that if we fed
it wood, it would burn on forever.
“When we have fire there is no need for swinging from tree to tree,
for we are safe on the ground.”
“Do the wild beasts fear the firebrands?” asked Rago.
“Yes,” answered the leader.
“May I use a firebrand?” asked Rago.
“Yes,” answered the leader. “You may light your own firebrand, and
you may help us feed the fire also.”
“I am glad we are going to live with you,” said Rago.
“We shall be glad to have you,” said the leader.
CHAPTER VII
THE FIRE
“He must have come from the thicket, because I didn’t see him until
he was upon me.”
“That certainly was a narrow escape,” said Rago.
“I am glad I heard you call.
“We must stay together now; my torch will protect both of us.”
“Let us find something to eat,” said Long-head.
So they walked on through the forest. They found nuts and roots
and fruits.
“Look out,” said Long-head, pointing to an opening in the hillside.
“That is the home of the cave bear. Don’t go too near.”
“The cave bears are asleep, aren’t they?” asked Rago.
“Yes, but they may wake up,” answered Long-head.
“What a fine basket,” said Rago. “I have never seen a rush basket
before.
“Now let me try to make one.” Then Rago wove a basket like the
one which Long-head had made.
“Mother will be pleased to see my basket,” said Rago.
“Now for the blueberry patch. We can fill our baskets.”
The two boys picked enough berries to fill their baskets.
“These baskets are very strong,” said Rago.
“Yes,” said Long-head. “Oak leaves make strong baskets, also.”
After they had filled their baskets the boys wandered about for a
while.
They watched the cattle going toward the stream for their evening’s
drink.
“Let us follow them,” said Long-head.
They enjoyed seeing the cattle wade knee-deep into the stream and
drink of the clear, cool water.
Both Rago and Long-head dipped their hands into the water. They
filled them and drank.
They were thirsty, for they had had no water all day.
“’Tis growing late,” said Long-head. “See, the sun is setting.
“The men will be coming back to the fire. Let us go back also.
“We shall have to tell them about the fierce wolf.”
“Will they play it?” asked Rago.
“Yes, indeed,” answered Long-head.
CHAPTER X
THE RETURN
When Rago and Long-head reached the fire, the men had already
returned.
They were sitting on the ground about the fire.
Rago ran up to Goni, saying, “Here are some fine blueberries, Goni. I
thought you would like them.”
“Where did you get the basket, Rago?” asked Goni.
“I made it from rushes,” said Rago. “Long-head showed me how to
make it.
“Some day I will show you how to make a basket just like this one.
“Where is baby sister?” asked Rago.
“She is in there,” said Goni, pointing to the shelter.
“The wind is so cold that the children are in there.”
Rago walked over toward Long-head. He was talking to the men in a
very excited way.
Rago knew he was telling them of his narrow escape from the wolf.
The men were listening and asking questions.
“You must be more careful in the future, Long-head,” they said.
“You are a brave boy, Rago,” said Strong-arm. “We are glad you have
come to live with us.”
This pleased Rago very much.
“Let us play it,” said the men.
So they pretended that one man was the fierce wolf, and another
played that he was Rago.
Then the man who played that he was Rago rushed upon the wolf,
waving his torch in his eyes.
The Tree-dwellers were very much interested.
“Now let us play it,” said one of the older boys.
So the boys had their hunting dance. They were glad to play what
the men had played.
After the hunting dance the men told about the animals which they
had seen that day.
They pretended that they were animals and showed just how the
animals acted.
Strong-arm held up the skin of a gopher which he had killed.
He told how the gophers lived among the tall grass, and how quick
one had to be to catch them.
Strong-arm showed the other Tree-dwellers how he had caught this
gopher.
Another man told how he had chased a cave bear back to its den
with his torch. He showed just how he had done this.
“Indeed, the fire is our friend,” he said, “for I could not have
frightened the cave bear without a torch.”
Rago listened while the man talked. He was anxious to learn, so he
could be brave.
One by one the men became drowsy and stretched themselves on
the ground near the fire.
“Where will you and Goni sleep tonight?” asked Rago of his mother.
“You need not be afraid to sleep on the ground. The fire will protect
you.”
“We shall sleep on the ground,” answered his mother. “Goni is not
afraid now.”
“Yes,” said Goni. “I shall sleep on the ground.”
One of the women took her place by the fire. She would watch all
night while the others slept.
Soon all was very quiet. The Tree-dwellers were fast asleep.
Only the sounds of the wild beasts could be heard as they hunted
their prey.
The Tree-dwellers were safe, because the fire would protect them.
TRANSCRIBER’S NOTE:
Obvious typographical errors have been corrected.
*** END OF THE PROJECT GUTENBERG EBOOK RAGO AND GONI,
THE TREE-DWELLER CHILDREN ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information