Instant Access to Learn Programming with C: An Easy Step-by-Step Self-Practice Book for Learning C 1st Edition Imran ebook Full Chapters
Instant Access to Learn Programming with C: An Easy Step-by-Step Self-Practice Book for Learning C 1st Edition Imran ebook Full Chapters
https://ebookmass.com
https://ebookmass.com/product/learn-programming-
with-c-an-easy-step-by-step-self-practice-book-
for-learning-c-1st-edition-imran/
https://ebookmass.com/product/microsoft-visual-c-step-by-step-9th-
edition-john-sharp/
testbankdeal.com
https://ebookmass.com/product/microsoft-visual-c-step-by-step-10th-
edition-john-sharp/
testbankdeal.com
https://ebookmass.com/product/easy-algebra-step-by-step-third-edition-
sandra-luna-mccune/
testbankdeal.com
McGraw-Hill's easy English step-by-step for ESL Learners.
Student Book. 2nd Edition Danielle Pelletier
https://ebookmass.com/product/mcgraw-hills-easy-english-step-by-step-
for-esl-learners-student-book-2nd-edition-danielle-pelletier/
testbankdeal.com
https://ebookmass.com/product/python-programming-3-books-
in-1-ultimate-beginners-intermediate-advanced-guide-to-learn-python-
step-by-step/
testbankdeal.com
https://ebookmass.com/product/game-theory-an-introduction-with-step-
by-step-examples-ana-espinola-arredondo/
testbankdeal.com
Authored by two standout professors in the feld of Computer Science and Technology
with extensive experience in instructing, Learn Programming with C: An Easy Step-by Step
Self-Practice Book for Learning C is a comprehensive and accessible guide to programming
with one of the most popular languages.
Meticulously illustrated with fgures and examples, this book is a comprehensive
guide to writing, editing, and executing C programs on diferent operating systems and
platforms, as well as how to embed C programs into other applications and how to create
one’s own library. A variety of questions and exercises are included in each chapter to test
the readers’ knowledge.
Written for the novice C programmer, especially undergraduate and graduate students,
this book’s line-by-line explanation of code and succinct writing style makes it an excellent
companion for classroom teaching, learning, and programming labs.
Sazzad M.S. Imran, Ph.D., is Professor in the Department of Electrical and Electronic
Engineering, University of Dhaka, Bangladesh. He completed his B.Sc. and M.S. degrees in
Applied Physics, Electronics & Communication Engineering from the University of Dhaka
and received his Ph.D. degree from the Optical Communication Lab of the Kanazawa
University, Japan. Dr. Imran has vast experience in teaching C/C++, Assembly Language,
MATLAB®, PSpice, AutoCAD, etc., at the university level (more at sazzadmsi.webnode.
com).
Preface, xi
CHAPTER 1 ◾ Introduction 1
1.1 HISTORY OF PROGRAMMING LANGUAGE 1
1.2 DIFFERENT TYPES OF PROGRAMMING LANGUAGE 2
1.3 IMPORTANCE OF PROGRAMMING 3
1.4 C PROGRAM STRUCTURE 3
1.5 STEP-BY-STEP TUTORIAL TO RUN A C PROGRAM 5
1.6 KEYWORDS 7
1.7 IDENTIFIERS 7
1.8 OPERATORS 8
1.9 OPERATOR PRECEDENCE IN C 9
1.10 VARIABLES 9
1.11 CONSTANTS 10
1.12 ESCAPE SEQUENCES 10
1.13 DATA TYPES 10
1.14 TYPE CASTING 11
1.15 EXAMPLES 12
EXERCISES 26
– MCQ with Answers 26
– Questions with Short Answers 37
– Problems to Practice 44
v
vi ◾ Contents
EXERCISES 294
– MCQ with Answers 294
– Questions with Short Answers 296
– Problems to Practice 299
PROJECT-13 560
PROJECT-14 560
PROJECT-15 560
PROJECT-16 560
PROJECT-17 560
PROJECT-18 561
PROJECT-19 561
PROJECT-20 561
PROJECT-21 561
PROJECT-22 561
INDEX, 563
Preface
xi
xii ◾ Preface
In conclusion, this book is a guided self-study for those interested in learning C by fol-
lowing a detailed, tutorial-type problem-solving book. We feel that it is a great book for
teachers to cover as a textbook for C programming language.
Introduction
DOI: 10.1201/9781003302629-1 1
2 ◾ Learn Programming with C
Smalltalk in 1972. Leafy, Logitech, and CrowdStrike were among the companies that used
it. In the same year, Dennis Ritchie created C for use with the Unix operating system at Bell
Telephone Laboratories. C is the basis for several modern languages, including C#, Java,
JavaScript, Perl, PHP, and Python. In 1972, IBM researchers Raymond Boyce and Donald
Chamberlain created SQL, which stood for Structured Query Language. It is a program
that lets you explore and edit data stored in databases.
Afer mathematician Ada Lovelace, Ada was created in 1980–1981 by a team directed
by Jean Ichbiah of CUU Honeywell Bull. Ada is an organized, statically typed, imperative,
wide-spectrum, and object-oriented high-level programming language used for air trafc
control systems. Bjarne Stroustrup created C++ afer modifying the C language at Bell
Labs in 1983. C++ is a high-performance programming language used in Microsof Ofce,
Adobe Photoshop, game engines, and other high-performance sofware. Brad Cox and
Tom Love created the Objective-C programming language in 1983 to construct sofware
for macOS and iOS. Larry Wall designed Perl in 1987 as a general-purpose, high-level pro-
gramming language for text editing.
Haskell, a general-purpose programming language, was created in 1990 to deal with
complex calculations, records, and number crunching. Guido Van Rossum created the
general-purpose, high-level programming language Python in 1991, and it is used by
Google, Yahoo, and Spotify. Visual Basic is a programming language created by Microsof
in 1991 that allows programmers to use a graphical user interface and is used in vari-
ous applications such as Word, Excel, and Access. Yukihiro Matsumoto designed Ruby
in 1993 as an interpreted high-level language for web application development. James
Gosling designed Java in 1995 as a general-purpose, high-level programming language
with cross-platform capabilities. Rasmus Lerdorf created the hypertext preprocessor PHP
in 1995 to create and maintain dynamic web pages and server-side applications. Brendan
Eich wrote JavaScript in 1995 for desktop widgets, dynamic web development, and PDF
documents.
Microsof created C# in 2000 by combining the computing power of C++ with the sim-
plicity of Visual Basic. Almost every Microsof product currently uses C#. In 2003, Martin
Odersky created Scala, which combines functional mathematical and object-oriented pro-
gramming. Scala is a Java-compatible programming language that is useful in Android
development. In 2003, James Strachan and Bob McWhirter created Groovy, a concise and
easy-to-learn language derived from Java. Google created Go in 2009, and it has since
gained popularity among Uber, Twitch, and Dropbox. Apple created Swif in 2014 to
replace C, C++, and Objective-C for desktop, mobile, and cloud applications.
arguments or parameters afer the function name, they are enclosed in parentheses; other-
wise, they are lef empty. Te body of the main() function is comprised of all the statements
between the opening and closing curly braces.
Write C-Program (or any name of your choice) on the ‘Project title:’ and choose the
folder (for example, C:\Users\SazzadImran\Desktop\) where you want to create the
project. Click Next>→Finish. A project or folder is created on the desktop.
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
6 ◾ Learn Programming with C
Step-3: Double click on C-Program on Workspace to select the project and click
File→New→Empty fle→Yes. Write a fle name of your choice (Example-1, for example)
and click Save.
An empty fle name Example-1.c is created and saved in the C-Program folder.
Step-4: Write your C program codes on the fle Example-1.c and save the fle.
Introduction ◾ 7
Step-5: Click Build→‘Compile current fle’ to compile the program. Correct any error(s)
or warning(s) on the codes. Correcting the errors is a must though it is optional to
correct the warnings. Recompile the program until we get 0 error(s) and 0 warning(s).
Step-6: Click Build→‘Build and run’ to execute the program. Te output screen will look
as follows:
1.6 KEYWORDS
In C programming, 32 reserved words have special meaning to compilers and are utilized
as a part of the syntax. Tese terms cannot be used as names or identifers for variables. Te
list of reserved C keywords is as follows:
auto, break, case, char, const, continue, default, do, int, long, register, return, short,
signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while, double,
else, enum, extern, foat, for, goto, if.
1.7 IDENTIFIERS
Variables, functions, structures, and other objects in a program are given unique names
called identifers. For example, in the statement of the preceding demo program
int age;
int is a keyword and age is an identifer assigned to a variable by the compiler to iden-
tify the entity uniquely. When naming an identifer, the following guidelines should be
observed.
(1) A valid identifer can include uppercase and lowercase letters, numbers, and
underscores.
(2) Te frst character cannot be a digit.
(3) We cannot use any keyword as an identifer.
(4) Te length of the identifer is unlimited.
Lady Molly had certainly been working too hard, and was in a
feeble state of health when we reached Porhoët the following 19th of
September, less than twenty-four hours before the eventful moment
when the old clock would reveal the will and testament of
Mademoiselle de Genneville.
We walked straight from the station to the presbytery, anxious to
see the Curé and to make all arrangements for to-morrow’s
business. To our terrible sorrow and distress, we were informed by
the housekeeper that the Curé was very seriously ill at the hospital at
Brest, whither he had been removed by the doctor’s orders.
This was the first inkling I had that things would not go as
smoothly as I had anticipated. Miss de Genneville’s dispositions with
regard to the sensational disclosure of her will had, to my mind, been
so ably taken that it had never struck me until now that the Marquise
de Terhoven and her precious son would make a desperate fight
before they gave up all thoughts of the coveted fortune.
I imagined the Marquis hemmed in on every side; any violence
offered against the Curé or Lady Molly when they entered the
château in order to accomplish the task allotted to them being visited
by the sending of the confession to Monsieur le Procureur de la
République, when prosecution for forgery would immediately follow.
Damage to the clock itself would be punished in the same way.
But I had never thought of sudden illnesses, of—heaven help us!
—poison or unaccountable accidents to either the Curé or to the
woman I loved best in all the world.
No wonder Lady Molly looked pale and fragile as, having thanked
the housekeeper, we found our way back in silence to the convent
where we had once again engaged rooms.
Somehow the hospitality shown us last year had lost something of
its cordiality. Moreover, our bedrooms this time did not communicate
with one another, but opened out independently on to a stone
passage.
The sister who showed us upstairs explained, somewhat
shamefacedly, that as the Mother Superior had not expected us, she
had let the room which was between our two bedrooms to a lady
visitor, who, however, was ill in bed at the present moment.
That sixth sense, of which so much has been said and written, but
which I will not attempt to explain, told me plainly enough that we
were no longer amidst friends in the convent.
Had bribery been at work? Was the lady visitor a spy set upon our
movements by the Terhovens? It was impossible to say. I could no
longer chase away the many gloomy forebodings which assailed me
the rest of that day and drove away sleep during the night. I can
assure you that in my heart I wished all eccentric old ladies and their
hidden wills at the bottom of the sea.
My dear lady was apparently also very deeply perturbed; any
attempt on my part to broach the subject of Miss de Genneville’s will
was promptly and authoritatively checked by her. At the same time I
knew her well enough to guess that all these nameless dangers
which seemed to have crept up round her only served to enhance
her determination to carry out her old friend’s dying wishes to the
letter.
We went to bed quite early; for the first time without that delightful
final gossip, when events, plans, surmises and work were freely
discussed between us. The unseen lady visitor in the room which
separated us acted as a wet blanket on our intimacy.
I stayed with Lady Molly until she was in bed. She hardly talked to
me whilst she undressed, but when I kissed her “good-night” she
whispered almost inaudibly right into my ear:
“The Terhoven faction are at work. They may waylay you and offer
you a bribe to keep me out of the château to-morrow. Pretend to fall
in with their views. Accept all bribes and place yourself at their
disposal. I must not say more now. We are being spied upon.”
That my lady was, as usual, right in her surmises was proved
within the next five minutes. I had slipped out of her room, and was
just going into mine, when I heard my name spoken hardly above a
whisper, whilst I felt my arm gently seized from behind.
An elderly, somewhat florid, woman stood before me attired in a
dingy-coloured dressing-gown. She was pointing towards my own
bedroom door, implying her desire to accompany me to my room.
Remembering my dear lady’s parting injunctions, I nodded in
acquiescence. She followed me, after having peered cautiously up
and down the passage.
Then, when the door was duly closed, and she was satisfied that
we were alone, she said very abruptly:
“Miss Granard, tell me! you are poor, eh?—a paid companion to
your rich friend, what?”
Still thinking of Lady Molly’s commands, I replied with a pathetic
sigh.
“Then,” said the old lady, eagerly, “would you like to earn fifty
thousand francs?”
The eagerness with which I responded “Rather!” apparently
pleased her, for she gave a sigh of satisfaction.
“You know the story of my sister’s will—of the clock?” she asked
eagerly: “of your friend’s rôle in this shameless business?”
Once more I nodded. I knew that my lady had guessed rightly.
This was the Marquise de Terhoven, planted here in the convent to
gain my confidence, to spy on Lady Molly, and to offer me a bribe.
Now for some clever tactics on my part.
“Can you prevent your friend from being at the château to-morrow
before one o’clock?” asked the Marquise.
“Easily,” I replied calmly.
“How?”
“She is ill, as you know. The doctor has ordered her a sleeping
draught. I administer it. I can arrange that she has a strong dose in
the morning instead of her other medicine. She will sleep till the late
afternoon.”
I rattled this off glibly in my best French. Madame la Marquise
heaved a deep sigh of relief.
“Ah! that is good!” she said. “Then listen to me. Do as I tell you,
and to-morrow you will be richer by fifty thousand francs. Come to
the château in the morning, dressed in your friend’s clothes. My son
will be there; together you will assist at the opening of the secret
doors, and when my son has wound up the old clock himself, he will
place fifty thousand francs in your hands.”
“But Monsieur le Curé?” I suggested tentatively.
“He is ill,” she replied curtly.
But as she spoke these three words there was such an evil sneer
in her face, such a look of cruel triumph in her eyes, that all my worst
suspicions were at once confirmed.
Had these people’s unscrupulous rapacity indeed bribed some
needy country practitioner to put the Curé temporarily out of the
way? It was too awful to think of, and I can tell you that I needed all
my presence of mind, all my desire to act my part bravely and
intelligently to the end, not to fly from this woman in horror.
She gave me a few more instructions with regard to the services
which she and her precious son would expect of me on the morrow.
It seems that, some time before her death, Miss de Genneville had
laid strict injunctions on two of her most trusted men-servants to
remain in the château, and to be on the watch on the eventful 20th
day of September of this year, lest any serious violence be done to
the English lady or to the Curé. It was with a view to allay any
suspicion which might arise in the minds of these two men that the
Marquis desired me to impersonate Lady Molly to-morrow, and to
enter with him—on seemingly friendly terms—the room where stood
the monumental clock.
For these services, together with those whereby Lady Molly was to
be sent into a drugged sleep whilst the theft of the will was being
carried through, I—Mary Granard—was to receive from Monsieur le
Marquis de Terhoven the sum of fifty thousand francs.
All these matters being settled to this wicked woman’s apparent
satisfaction, she presently took hold of both my hands, shook them
warmly, and called me her dearest friend; assured me of everlasting
gratitude, and finally, to my intense relief, slipped noiselessly out of
my room.
4