100% found this document useful (3 votes)
17 views

Programming in C Third Edition Kamthane download

The document is the third edition of 'Programming in C' by Ashok N. Kamthane, which covers fundamental concepts of the C programming language. It includes topics such as data types, operators, control statements, functions, and data structures, along with exercises for practice. The book is published by Pearson India Education Services and is intended for educational purposes, with restrictions on reproduction and distribution.

Uploaded by

sueszklavet6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
17 views

Programming in C Third Edition Kamthane download

The document is the third edition of 'Programming in C' by Ashok N. Kamthane, which covers fundamental concepts of the C programming language. It includes topics such as data types, operators, control statements, functions, and data structures, along with exercises for practice. The book is published by Pearson India Education Services and is intended for educational purposes, with restrictions on reproduction and distribution.

Uploaded by

sueszklavet6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

Programming in C Third Edition Kamthane install

download

https://ebookmeta.com/product/programming-in-c-third-edition-
kamthane/

Download more ebook from https://ebookmeta.com


PROGRAMMING IN C
third Edition

Ashok N. Kamthane
Associate Professor
Shri Guru Gobind Singhji Institute of Engineering
and Technology, Nanded, Maharashtra, India

A01_KAMT3553_02_SE_FM.indd 1 5/17/2015 8:59:35 AM


DEDI CAT I O N
To My Beloved Late Grandfather
Jagganath Kamthane

Associate Editor—Acquisitions: Neha Goomer


Editor—Production: G Sharmilee

Copyright © 2015 Pearson India Education Services Pvt. Ltd

Copyright © 2006, 2012 Dorling Kindersley (India) Pvt. Ltd


This book is sold subject to the condition that it shall not, by way of trade or otherwise, be lent, resold,
hired out, or otherwise circulated without the publisher’s prior written consent in any form of binding
or cover other than that in which it is published and without a similar condition including this condition
being imposed on the subsequent purchaser and without limiting the rights under copyright reserved
above, no part of this publication may be reproduced, stored in or introduced into a retrieval system, or
transmitted in any form or by any means (electronic, mechanical, photocopying, recording or otherwise),
without the prior written permission of both the copyright owner and the publisher of this book.

ISBN 978-93-325-4355-3

First Impression

Published by Pearson India Education Services Pvt. Ltd, CIN: U72200TN2005PTC057128, formerly
known as TutorVista Global Pvt. Ltd, licensee of Pearson Education in South Asia.

Head Office: A-8(A), 7th Floor, Knowledge Boulevard, Sector 62, Noida 201 309, Uttar Pradesh, India.
Registered Office: Module G4, Ground Floor, Elnet Software City, TS-140, Block 2 & 9,
Rajiv Gandhi Salai, Taramani, Chennai 600 113, Tamil Nadu, India.
Fax: 080-30461003, Phone: 080-30461060
www.pearson.co.in, Email: companysecretary.india@pearson.com

Compositor: Mukesh Technologies Pvt. Ltd


Printed in India

A01_KAMT3553_02_SE_FM.indd 2 5/17/2015 8:59:36 AM


Contents

Preface xi
Acknowledgements xiv
About the Author xv

1 Basics and Introduction to C ............................................................... 2


1.1 Why to Use Computers? 3
1.2 Basics of a Computer 3
1.3 Latest Computers 5
1.4 Introduction to C 6
1.5 About ANSI C Standard 7
1.6 Machine, Assembly and High-Level Language 7
1.6.1 Assembly Language 8
1.6.2 High-Level Language 8

1.7 Assembler, Compiler and Interpreter 8


1.8 Structure of a C Program 10
1.9 Programming Rules 12
1.10 Executing the C Program 12
1.11 Standard Directories 16
1.12 The First C Program 16
1.13 Advantages of C 17
1.14 Header Files 17
1.15 Algorithm 18
1.15.1 Program Design 20

1.16 Classification of Algorithms 21


1.17 Flowcharts 22
1.18 Pseudocode 26
Summary 28
Exercises 28

2 The C Declarations ............................................................................. 32


2.1 Introduction 33
2.2 The C Character Set 33
2.3 Delimiters 34

A01_KAMT3553_02_SE_FM.indd 3 5/17/2015 8:59:36 AM


iv Contents

2.4 Types of Tokens 35


2.5 The C Keywords 35
2.6 Identifiers 35
2.7 Constants 36
2.7.1 Numerical Constants 37
2.7.2 Character Constant 38

2.8 Variables 39
2.9 Rules for Defining Variables 39
2.10 Data Types 40
2.11 C Data Types 41
2.12 Integer and Float Number Representations 43
2.12.1 Integer Representation 43
2.12.2 Floating-Point Representation 44

2.13 Declaring Variables 44


2.14 Initializing Variables 45
2.15 Dynamic Initialization 46
2.16 Type Modifiers 46
2.17 Type Conversion 47
2.18 Wrapping Around 49
2.19 Constant and Volatile Variables 50
2.19.1 Constant Variable 50
2.19.2 Volatile Variable 50

Summary 51
Exercises 52

3 Operators and Expressions �������������������������������������������������������������� 58


3.1 Introduction 59
3.2 Operator Precedence 59
3.3 Associativity 62
3.4 Comma and Conditional Operator 63
3.5 Arithmetic Operators 64
3.6 Relational Operators 67
3.7 Assignment Operators and Expressions 68
3.8 Logical Operators 71
3.9 Bitwise Operators 74
Summary 80
Exercises 80

A01_KAMT3553_02_SE_FM.indd 4 5/17/2015 8:59:36 AM


Contents v

4 Input and Output in C ������������������������������������������������������������������������ 84


4.1 Introduction 85
4.2 Formatted Functions 86
4.3 Flags, Widths and Precision with Format String 88
4.4 Unformatted Functions 99
4.5 Commonly Used Library Functions 104
4.6 Strong Points for Understandability 105
Summary 106
Exercises 106

5 Decision Statements ����������������������������������������������������������������������� 112


5.1 Introduction 113
5.2 The if Statement 114
5.3 The if–else Statement 116
5.4 Nested if–else Statements 120
5.5 The if-else-if Ladder Statement 121
5.6 The break Statement 129
5.7 The continue Statement 130
5.8 The goto Statement 130
5.9 The switch Statement 132
5.10 Nested switch case 144
5.11 The switch case and nested ifs 146
Summary 147
Exercises 148

6 Loop Control ������������������������������������������������������������������������������������ 154


6.1 Introduction
6.1.1 What is a Loop?
155
155

6.2 The for Loop 156


6.3 Nested for Loops 172
6.4 The while Loop 194
6.5 The do-while Loop 207
6.6 The  while  Loop within the  do-while  Loop 212
6.7 Bohm and Jacopini’s Theory 213
Summary 213
Exercises 213

A01_KAMT3553_02_SE_FM.indd 5 5/17/2015 8:59:36 AM


vi Contents

7 Data Structure: Array ���������������������������������������������������������������������� 220


7.1 Introduction 221
7.2 Array Declaration 221
7.3 Array Initialization 222
7.4 Array Terminology 223
7.5 Characteristics of an Array 224
7.6 One-Dimensional Array 226
7.7 One-Dimensional Array and Operations 238
7.8 Operations with Arrays 240
7.9 Predefined Streams 246
7.10 Two-Dimensional Array and Operations 251
7.10.1 Insert Operation with Two-Dimensional Array 253
7.10.2 Delete Operation with Two-Dimensional Array 255

7.11 Three- or Multi-Dimensional Arrays 269


7.12 The sscanf() and sprintf() Functions 274
7.13 Drawbacks of Linear Arrays 276
Summary 276
Exercises 277

8 Strings and Standard Functions �������������������������������������������������������� 286


8.1 Introduction 287
8.2 Declaration and Initialization of String 287
8.3 Display of Strings with Different Formats 289
8.4 String Standard Functions 291
8.5 String Conversion Functions 315
8.6 Memory Functions 316
8.7 Applications of Strings 318
Summary 328
Exercises 328

9 Pointers ������������������������������������������������������������������������������������������� 336


9.1 Introduction 337
9.2 Features of Pointers 338
9.3 Pointers and Address 338
9.4 Pointer Declaration 339
9.5 The Void Pointers 345
9.6 Wild Pointers 346
9.7 Constant Pointers 347
9.8 Arithmetic Operations with Pointers 348

A01_KAMT3553_02_SE_FM.indd 6 5/17/2015 8:59:36 AM


Contents vii

9.9 Pointers and Arrays 352


9.10 Pointers and Two-Dimensional Arrays 357
9.11 Pointers and Multi-Dimensional Arrays 358
9.12 Array of Pointers 360
9.13 Pointers to Pointers 362
9.14 Pointers and Strings 364
Summary 371
Exercises 371

10 Functions ����������������������������������������������������������������������������������������� 378


10.1 Introduction 379
10.2 Basics of a Function 379
10.2.1 Why Use Functions? 379
10.2.2 How a Function Works? 380

10.3 Function Definition 380


10.4 The return Statement 384
10.5 Types of Functions 386
10.6 Call by Value and Reference 393
10.7 Function Returning More Values 395
10.8 Function as an Argument 396
10.9 Function with Operators 399
10.10 Function and Decision Statements 406
10.11 Function and Loop Statements 409
10.12 Functions with Arrays and Pointers 412
10.13 Passing Array to a Function 418
10.14 Nested Functions 420
10.15 Recursion 422
10.16 Types of Recursion 424
10.17 Rules for Recursive Function 425
10.18 Direct Recursion 427
10.19 Indirect Recursion 428
10.20 Recursion Versus Iterations 430
10.21 The Towers of Hanoi 432
10.22 Advantages and Disadvantages of Recursion 435
10.23 Efficiency of Recursion 436
10.24 Library Functions 437
Summary 438
Exercises 438

A01_KAMT3553_02_SE_FM.indd 7 5/17/2015 8:59:36 AM


viii Contents

11 Storage Classes ������������������������������������������������������������������������������ 446


11.1 Introduction
11.1.1 Lifetime of a Variable
447
447
11.1.2 Visibility of a Variable 448

11.2 Automatic Variables 448


11.3 External Variables 450
11.4 Static Variables 453
11.5 Static External Variables 454
11.6 Register Variables 455
Summary 456
Exercises 456

12 Preprocessor Directives ����������������������������������������������������������������� 462


12.1 Introduction 463
12.2 The #define Directive 463
12.3 Undefining a Macro 466
12.4 Token Pasting and Stringizing Operators 467
12.5 The #include Directive 468
12.6 Conditional Compilation 469
12.7 The #ifndef Directive 471
12.8 The #error Directive 472
12.9 The #line Directive 473
12.10 The #pragma inline Directive 473
12.11 The #pragma saveregs 473
12.12 The #pragma Directive 473
12.13 The Predefined Macros in ANSI and Turbo-C 475
12.14 Standard I/O Predefined Streams in stdio.h 478
12.15 The Predefined Marcos in ctype.h 478
12.16 Assertions 480
Summary 481
Exercises 481

13 Structure and Union ������������������������������������������������������������������������ 490


13.1 Introduction 491
13.2 Features of Structures 491
13.3 Declaration and Initialization of Structures 492
13.4 Structure within Structure 496

A01_KAMT3553_02_SE_FM.indd 8 5/17/2015 8:59:36 AM


Contents ix

13.5 Array of Structures 498


13.6 Pointer to Structure 501
13.7 Structure and Functions 504
13.8 typedef 506
13.9 Bit Fields 510
13.10 Enumerated Data Type 513
13.11 Union 517
13.12 Calling BIOS and DOS Services 518
13.13 Union of Structures 524
Summary 524
Exercises 525

14 Files ������������������������������������������������������������������������������������������������� 532


14.1 Introduction of a File 533
14.2 Definition of File 533
14.3 Streams and File Types 534
14.3.1 File Types 534
14.4 Steps for File Operations 535
14.4.1 Opening of File 536
14.4.2 Reading a File 536
14.4.3 Closing a File 536
14.4.4 Text Modes 537
14.4.5 Binary Modes 543
14.5 File I/O 545
14.6 Structures Read and Write 553
14.7 Other File Function 558
14.8 Searching Errors in Reading/Writing Files 561
14.9 Low-Level Disk I/O 572
14.10 Command Line Arguments 576
14.11 Application of Command Line Arguments 577
14.12 Environment Variables 579
14.13 I/O Redirection 580
Summary 582
Exercises 582

15 Graphics ������������������������������������������������������������������������������������������ 590


15.1 Introduction 591
15.2 Initialization of Graphics 591
15.3 Few Graphics Functions 591

A01_KAMT3553_02_SE_FM.indd 9 5/17/2015 8:59:36 AM


x Contents

15.4 Programs Using Library Functions 593


15.4.1 Program on Moving Moon 596

15.5 Working with Text 598


15.5.1 Stylish Lines 599

15.6 Filling Patterns with Different Colours and Styles 600


15.7 Mouse Programming 604
15.8 Drawing Non-common Figures 607
Summary 608
Exercises 608

16 Dynamic Memory Allocation and Linked List �������������������������������� 612


16.1 Dynamic Memory Allocation 613
16.2 Memory Models 613
16.3 Memory Allocation Functions 614
16.4 List 621
16.5 Traversal of a List 621
16.6 Searching and Retrieving an Element 622
16.7 Predecessor and Successor 623
16.8 Insertion 624
16.9 Linked Lists 626
16.10 Linked List with and without Header 627
16.10.1 Linked List with Header 627

Summary 636
Exercises 637

Appendix A ��������������������������������������������������������������������������������� 641


American Standard Code for Information Interchange 641

Appendix B ��������������������������������������������������������������������������������� 649


Priority of Operators and Their Clubbing 649

Appendix C ��������������������������������������������������������������������������������� 651


Header Files and Standard Library Functions 651

Appendix D  ��������������������������������������������������������������������������������� 655


ROM-BIOS Services 655

Appendix E ��������������������������������������������������������������������������������� 657


Scan Codes of Keyboard Keys 657
Index ��������������������������������������������������������������������������������������� 660

A01_KAMT3553_02_SE_FM.indd 10 5/17/2015 8:59:36 AM


Preface

I am indeed very delighted to present the third edition of Programming in C with elaborated ­c oncepts
supported with more solved and unsolved problems. I have tried to make the book friendly using
simple and lucid language. In this edition, a chapter on Graphics with thought provoking questions
and programming examples are added.
This book is proposed for beginners, intermediate level students, and for all those who are
pursing education in computers. It would be extremely useful for the students who enroll for
diploma, degree in science and engineering, certificate courses in computer languages in training
institutes or those who appear for the C aptitude tests/interviews on C Language conducted by
various software companies and enhance their C knowledge. It can be used as a reference book for
those who want to learn or enrich their knowledge in C.
All the programs given in this book are compiled and run on Turbo C compiler. A few applications
are provided in this book which are fully tested and run on Turbo C compiler. The programmer can
develop advanced applications based on real-life problems using basics of C language. It contains
numerous examples which include solved and unsolved programming exercises that make the book
most interesting. Multiple choice questions are also provided at the end of each chapter for testing the
skills of a programmer.
An attempt has been made to cover the C syllabi of different branches of various universities.
Hence this book can be adopted as a text or a reference book in engineering/degree/diploma and other
courses.
In order to bridge the gap between theory and practical, each concept is explained at length in an
easy-to-understand manner supported with numerous worked-out examples and programs. The book
contains solved illustrative problems and exercises. The programmer can run the solved programs, can
see the output and enjoy the concepts of C.

BOOK ORGANIZATION
The first chapter describes the fundamental concepts of a computer, components of a computer, an
overview of compilers and interpreters, structure of a ‘C’ program, programming rules, how to execute
the program, and flowchart for execution of a program. This chapter also presents the techniques of
solving a problem using algorithm and flowchart.
Chapter 2 explains the fundamentals of ‘C’. These concepts are essential for writing programs
and contain character set supported by C language. Various delimiters used with ‘C’ statements,
keywords and identifiers are also provided. Different constants, variables and data types supported
by C are also given. This chapter covers the rules for defining variables and methods to initialize
them. Dynamic initialization is also presented in this chapter. Type conversion of a variable, type
modifiers and wrapping around, constant and volatile variables are also explained.
Chapter 3 covers various C operators and their priorities. This chapter presents arithmetic,
relational and logical operators. It also embodies increment, decrement (unary operators) and
assignment operators. Other operators such as comma, conditional operator and bitwise operators are
presented with programming examples.

A01_KAMT3553_02_SE_FM.indd 11 5/17/2015 8:59:36 AM


xii Preface

Chapter 4 deals with formatted input and output functions such as scanf()and printf()
functions. The unformatted functions such as putchar(), getche() and gets() are described
in this chapter. Different data types and conversion symbols to be used in the C programs have also
been elaborated. The special symbols such as escape sequences together with their applications are
also discussed. Few of the commonly used library functions to be used in the programs such as
clrscr() and exit() are also described.
Chapter 5 is essential for knowing the decision-making statements in C language. This chapter
presents how to transfer the control from one part to the other part of the program. The programmer
can make the program powerful by using control statements such as if, if-else, nested if-else
statements and switch case. To change the flow of the program, the programmer can use keywords
such as break, continue and goto.
Chapter 6 is devoted to control loop structures in which how statements are executed several times
until a condition is satisfied. In this chapter, the reader follows program loop which is also known as
iterative structure or repetitive structure. Three types of loop control statements are illustrated with
for, while and do-while programming examples. Syntaxes of these control statements are briefed
together with programming examples. The other statements such as the break,continue and goto
statements are also narrated.
Chapter 7 deals with the array in which the reader can follow how to initialize array in different
ways. The theme of this chapter is to understand the array declaration, initialization, accessing array
elements and operations on array elements. How to specify the elements of one-, two- and three- or
multi-dimensional arrays are explained in detail together with ample examples. The functions such
as sscanf() and sprintf()are demonstrated through programming examples. The reader can
develop programs after learning this chapter on arrays. This chapter also gives an overview of the
string. It covers operations on array such as deletion, insertion and searching an element in the array
and how to traverse all the array elements.
Chapter 8 is focused on strings. This chapter teaches you how to learn declaration and initialization
of a string. It is also very important to identify the end of the string. This is followed by NULL
(‘\0’) character. The various formats for display of the strings are demonstrated through numerous
examples.
String handling has strong impact in real-life string problems such as conversion of lower to upper
case, reversing, concatenation, comparing, searching and replacing of string elements. It is also discussed
how to perform these operations with and without standard library functions. Memory functions such
as memcpy(), memove() and memchr()are also illustrated together with programming examples.
Chapter 9 deals with the most important feature of the C language, i.e. pointer, it is important but
difficult to understand easily. The reader is made familiar with pointers with numerous examples. The
reader is brought to light about declaration and initialization of pointers, and how to access variables
using pointers. How pointers are used to allocate memory dynamically at run time is also illustrated
using memory allocation functions such as malloc() and calloc() functions. How memory is
handled efficiently with pointers is also explained. This chapter consists of arithmetic operations on
pointers, pointers and arrays, pointers to pointers and pointers to strings. Memory models are also
explained.
Chapter 10 is one more important chapter on functions. How a large size program is divided in
smaller ones and how a modular program should be developed is learnt in this chapter. Programmer
learns the definition and declaration of function. What are the return statements, types of functions
and functions with passing arguments are described in detail. What do you mean by “call by value”
and “call by reference”? — Their answers are given with many programming examples. This chapter
also incorporates functions and loop statements, function and arrays and association of functions and
pointers.

A01_KAMT3553_02_SE_FM.indd 12 5/17/2015 8:59:37 AM


Preface xiii

The reader should know that the function always returns an integer value. Besides a function can
also return a non-integer data type but function prototype needs to be initialized at the beginning of the
program. The recursive nature of function is also explained with suitable example. Direct and indirect
recursive functions have been explained with programming examples.
Chapter 11 enlightens on the variables used in C in different situations. It also covers types of
variables such as local and global variables. The various storage classes of a variable are also covered
in this chapter. Explanations on auto, extern, static and register variables are also presented
in this chapter.
Chapter 12 narrates how to make use of preprocessor directives and how various macros are to
be used. This chapter enlightens preprocessor directives such as #define, #undef, #include,
#line, token pasting and stringizing operations and conditional compilation through C are illustrated.
It covers #define directive, undef macro, include directive, predefined macros in ANSI and
Turbo C. A reader learns how to display programmer’s own error messages using #error directive
and making various warnings on/off displayed by compiler using #pragma directive. You are exposed
to predefined macors in ctype.h in this chapter.
Chapter 13 is on structures and unions. A reader can get derived data type using structures and
unions. User can decide the heterogeneous data types to be included in the body of a structure. Use
of dot operator (.) and pointer (->) are explained for accessing members of structure. Declaration and
initialization of structure and union are also explained. The typedef facility can be used for creating
user-defined data types and illustrated with many examples. Enumerated data type and union are the
important subtitles of this chapter. Enumerated data type provides user-defined data types. Union is a
principal method by which the programmer can derive dissimilar data types. The last but not the least
the DOS and ROM-BIOS functions and their applications are also explained.
Chapter 14 is on files. This chapter explains the procedure for opening a file, storing information
and reading. How to read a file and how to append information are explained in this chapter. Many file
handling commands are also discussed. Text and binary files are explained. Command line arguments
to accept arguments from command prompt are described. Simulation of various DOS commands
with examples is also narrated. A reader is also made familiar with I/O redirections in which MSDOS
redirects to send the result to disk instead of seeing information on monitor.
Chapter 15 is on graphics. How to draw various figures/images using C library graphics functions
are to be studied from graphics chapter. This chapter enlightens the reader about the initialization of
graphics with library graphics functions and number of programming examples. Few programs have
been provided on mouse programming.
Chapter 16 enlightens the reader on dynamic memory allocations, memory models and linked
lists. Dynamic memory allocation deals with memory functions such as malloc(), calloc(),
coreleft() and realloc() and release the allocated memory using free() function. The
linked list is described in brief in this chapter. In the linked list, creation of linked list, traversing,
searching, inserting and deleting an element are described with figures and programming examples.
Utmost care has been taken to write third edition of the book in order to make it error free. The
suggestions and feedback for the improvement of the book are always welcome, the readers can
directly mail me at ankamthane@gmail.com.
Ashok N. Kamthane

A01_KAMT3553_02_SE_FM.indd 13 5/17/2015 8:59:37 AM


Acknowledgements

I would like to thank all those who have encouraged me, especially Professor B.M. Naik, former
principal of Shri Guru Gobind Singhji Institute of Engineering and Technology, who has been
always a source of inspiration.
Special thanks are due to members of board of governors of SGGS institute who motivated
me for writing this book, Baba Kalyani, Chairman and Managing Director of Bharat Forge Ltd
Pune, Ram Bhogle, C.Y. Gavhane, Mr Kamlesh Pande, Sanjay Kumar, Dr Nirmal Singh Sehra, and
Director of our Institute Dr L.M. Waghmare.
My sincere thanks to Professor S.D. Mahajan, Director of Technical Education, Maharashtra
State, and ex-Board of Governors of this college, Dr M.B. Kinhalkar, Former Home Minister and
ex-Principal, Dr T.R. Sontakke for inspiring me to write this book.
I am grateful to all my colleagues, friends and students, who extended morale support,
Dr Y.V. Joshi, Dr R.R. Manthalkar, Dr S.S. Gajre, Dr S.V. Bonde, Dr P.G. Jadhav, Professor N.G.
Megde, Professor P.S. Nalawade, Dr A.R. Patil, Dr A.B. Gonde, Dr M.B. Kokre, Dr U.V. Kulkarni,
Dr P. Pramanik, Dr V.M. Nandedkar, Dr A.V. Nandedkar, Dr B.M. Patre, Dr S.T. Hamde, Dr R.C.
Thool, Dr V.R. Thool, Mrs U.R. Kamble, Dr D.D. Doye, Dr V.G. Asutkar, Professor R.K. Chavan,
Professor Ghanwat Vijay, Dr V.K. Joshi, Dr S.G. Kahalekar, Dr A. Chakraborty, Dr P. Kar, Dr P.G.
Solankar, Dr B.M. Dabde, Dr M.L. Waikar, Dr R.S. Holambe, Dr J.V.L. Venkatesh, Mrs S.S.
Kandhare, Professor S.S. Hatkar, Narayan Patil, Dr P.D. Dahe, Dr P.D. Ullagadi, Dr P.B. Londhe,
Dr A.S. Sontakke, Professor A.M. Bainwad, Professor Deepak Bacchewar, Professor R.P. Parvekar,
Professor N.M. Khandare, Dr V.B.Tungikar, Dr R.N. Joshi, Dr L.G. Patil, Professor A.I. Tamboli,
Mr Bhalerao M.V. and Professor S.B. Dethe.
I am also thankful to my friends, Professor S.L. Kotgire, Maruti Damkondawar, G.M. Narlawar,
Anil Joshi, D.V. Deshpande, Professor Balaji Bacchewar, M.M. Jahagirdar, L.M. Buddhewar,
K.M. Buddhewar, S.R. Kokane, Ganpat Shinde, M.G. Yeramwar, S.R. Tumma, S.P. Tokalwad,
P.R. Navghare, Somajawar H.S. and Annes for their morale support.
I am thankful to the wonderful editorial team of Pearson Education for specific invaluable inputs
and bringing this book out in a record time.
I also express my thanks to my son Lecturer Amit, students Jadhav Gopal and Wanjare Sainath
for their critical review and suggesting improvements.
Last but not the least, my thanks are due to my wife Surekha for her patience and support. My son
Amol, daughter Sangita and daughter-in-law Swaroopa were of great help and supported me all the
times.

Ashok N. Kamthane

A01_KAMT3553_02_SE_FM.indd 14 5/17/2015 8:59:37 AM


About the Author

Ashok N. Kamthane is presently working as an associate professor in Department of Electronics and


Telecommunication Engineering at Shri Guru Gobind Singhji Institute of Engineering and Technology,
Nanded, Maharashtra. He has over 32 years of teaching experience. He was associated with the
development of hardware and software using 8051 on acoustic transceiver system for submarines.
Professor Kamthane is also the author of bestselling books Object-Oriented Programming with
ANSI and Turbo C++; Introduction to Data Structures in C; and C Programming: Test Your Skills,
published by Pearson Education.

A01_KAMT3553_02_SE_FM.indd 15 5/17/2015 8:59:37 AM


This page is intentionally left blank
CHAPTER

1 Basics and
Introduction to C
Chapter Outline
1.1 Why to use Computers?
1.2 Basics of a Computer
1.3 Latest Computers
1.4 Introduction to C
1.5 About ANSI C Standard
1.6 Machine, Assembly and High-Level Language
1.7 Assembler, Compiler and Interpreter
1.8 Structure of a C Program
1.9 Programming Rules
1.10 Executing the C Program
1.11 Standard Directories
1.12 The First C Program
1.13 Advantages of C
1.14 Header Files
1.15 Algorithm
1.16 Classification of Algorithms
1.17 Flowcharts
1.18 Pseudocode

M01_KAMT3553_02_SE_C01.indd 2 5/17/2015 9:04:16 AM


Basics and Introduction to C 3

1.1 Why to Use Computers?


Computers play a vital role in the socioeconomic progress of a country. Every nation is paying much
importance to computer literacy. Progress of individuals, surrounding region, nation and of the world
is ensured only with the introduction and use of computers. In every walk of life, computers are being
used increasingly. In every part of the world, computers are employed to increase the overall produc-
tivity. Moreover, the quality of the products due to application of computers is substantially improved.
The impact of computers is very high on mass education, entertainment and productivity in all fields.
With the use of computers the cost of production reduces drastically, a lot of time is saved and the best
quality is ensured.
With the adoption of the policy of liberalization, privatization and globalization by the govern-
ments all over the world, it is necessary to become competitive in the market. Luxurious survival is
not easy as was possible in ancient days. With land, labour, muscle power and capital, economy can
certainly be boosted to a certain degree, but the intellectual power is highly superior to all these assets.
With some know-how (for the common users) and a lot of technical innovations (by the developers),
numerical problems, business transactions and scientific applications, can be computed in almost no
time. A computer does various tasks on the basis of programs. Intellectual computer is certainly a
powerful gadget but human intellectual capability is much higher than that of a computer. Thus, com-
puter does not have its own brain. Brainpower of computer is limited. Thus, human intellectual power
is further reinforced by the use of computers frequently in the day-to-day life. By learning program-
ming languages, developing software packages and using hardware of computers, one can make his/
her life and nation prosperous.

1.2 Basics of a Computer


Data to be processed by a computer appears in different forms, such as numeric, alphabetical char-
acters either in uppercase or in lowercase, special characters and multimedia. Research applications
in universities and colleges frequently use numeric data on large scales, whereas businessmen and
people in the corporate sector use both numeric and
character data. However, in animation multimedia is
used which include text, video and audio. Central
A computer is a programmable ­electronic Input Processor Output
­machine that accepts instructions and data through Unit
input devices, manipulating data ­according to
­instructions and finally providing result to the
output device. The result can be stored in memo-
ry or sent to the output device. Figure 1.1 shows Memory
the conventional block diagram of a ­conventional
computer.
Figure 1.2 shows a computer system contain- Figure 1.1 Block diagram of a conventional computer
ing a monitor, a keyboard and a rectangular box
comprising CPU on the motherboard.
In brief, the various blocks of a computer are described as follows.
Input Device: Input device is used to accept the data and instructions in to the computer. Through
the input device, i.e. keyboard, instructions and data are stored in a computer’s memory. Stored
­instructions are further read by the computer from its memory and thus a computer manipulates
the data according to the instructions. The various input devices that can be used in a computer are

M01_KAMT3553_02_SE_C01.indd 3 5/17/2015 9:04:17 AM


4 Programming in C

k­ eyboards, mouse, analog-to-digital converters,


light pen, track ball, optical character reader and
Interface
scanner. Figure 1.3 shows the input devices of
a computer. Floppy, compact disc, etc. can be
used as input or output device.
Central Processor Unit: CPU is the abbrevia-
tion for central processor unit. It is the heart of the
computer system. It is a hardware device in the
Figure 1.2 computer system

CD Keyboard Mouse Floppy Microphone Pen Drive

Figure 1.3 Input devices of a computer

computer and quite often it called as microprocessor chip. Since it is a tiny chip hence called as mi-
croprocessor chip. This chip is produced from silicon vapor over which millions of transistors are
mounted with modern fabrication techniques.
The brain of the computer is CPU. This chip is responsible to interpret and execute the instruc-
tions. It comprises arithmetic and logical unit, registers and control unit. The arithmetic and logical
unit performs various arithmetic and logical operations on the data based upon the instructions. The
control unit generates the timing and control signals for carrying out operations within the processor.
Registers are used for holding the instructions and storing the results temporarily. Instructions are
stored in the memory and they are fetched one by one and executed by the processor.
Output Device: The output device is used to display the results on the screen or to send the data to
an output device. The processed data is ultimately sent to the output device by the computer. The out-
put device can be a monitor, a printer, an LED, seven-segment display, D to A converter, plotter, and
so on. Figure 1.4 shows different output devices of a computer.

Printer CD Floppy Monitor Speaker Hard-Disk

Figure 1.4 Output devices of a computer

Memory: Memory is used to store the program. There are two types of semi-conductor memories.
They are as follows:
(i) RAM (Random access memory)
(ii) ROM (Read only memory)

M01_KAMT3553_02_SE_C01.indd 4 5/17/2015 9:04:18 AM


Basics and Introduction to C 5

semi-conductor memory is used for storing the instructions and data in the form of ones and zeros.
The memory can be called user’s memory or read–write memory. Processor first reads the instructions
and data from the primary memory (semi-conductor memory). Then, it executes the instructions.
One more memory device used by a computer is called read only memory (ROM). This contains
a fixed software program for providing certain operations. This is non-volatile memory. Its contents
cannot be eliminated when power supply goes off. The basic input–output system (BIOS) is a soft-
ware used to control various peripheral devices such as a keyboard, a monitor, a printer, a mouse,
ports including serial and parallel ports. In fact, this is an operating system. It is possible to access the
users’ written programs, i.e. by loading a file, saving it and doing modifications to it in the later stage.
As soon as a personal computer is switched on, the software gets booted from ROM. Thus, various
functions are assigned to all supporting peripherals of a central processing unit (CPU) and easy inter-
actions are provided to the user by BIOS while booting the system.
For storing volumous data, secondery storage devices can be used. They are optical disk, ­magnetic
disc, tapes, etc.

1.3 Latest Computers


The discussion on the various types of computers existing in the market is beyond the scope in this book.
Latest computers available in the market are in various shapes and sizes. These computers are just like
notebooks or even require lesser space than the notebook. They are handy, light weighted and portable.
Because of these reasons many computer users now carry laptops while travelling for their day-to-day
work. In the next couple of years, it is predicted that every school-going child would be using a laptop or
palmtop, and these devices would be sold just like hot cakes in the market with affordable prizes. A lot
of research work is going on in the foreign and Indian Universities, institutes and industries on the reduc-
tion of the size of a computer, building more functions in it with low cost, minimum battery power for
operating it for large duration in the absence of A.C. mains power supply. In a couple of years, laptops and
palmtops would be flooded in the market. These notebook-shaped laptops are as powerful as desktop com-
puters. In other words, the computing power of a laptop would be advancing to that of desktop computers
and minicomputers. They are used for the purpose of text processing, web surfing, multimedia operation,
image processing and so on. Performances of these computers are constantly improving, and the cost is
drastically reducing. A wireless network can be formed easily with laptops with the Bluetooth technology.
Wifi wireless network is quite popular nowadays, and there we use these computers quite often.
Typical specifications of a laptop computer are as follows,
• Processor: Intel Core i7 ( 8M cache,2.80GHz) OR AMD
• RAM: Minimum 2 GB to Maximum 16 GB
• Hard disk: Minimum 320 GB up to 1 TB or higher
• CD/DVD Drive: Dual Layer DVD+/-RW Drive, SuperDrive, Bluetooth and Camera
• Screen Size: 15.6” up to 23” Flat screen with LCD/LED display
• Ethernet: 10/100/1000 Mbps Ethernet
• Port: USB 3.0
• Graphics Card: From 520 MB or higher
• Rechargeable Battery back up
• Operating system such as windows XP/ windows 7/ Linux
For simpler application, one can go for Celeron-based laptop where heat
­generated by the processor is little. Pentium processors are used only for
dedicated applications. Heat generated by this kind of laptop is more and
battery is to be frequently charged (Figure 1.5). Figure 1.5 The laptop

M01_KAMT3553_02_SE_C01.indd 5 5/17/2015 9:04:18 AM


6 Programming in C

1.4 Introduction to C BCPL B
C is one of the most popular general-purpose programming ­languages.
C language has been designed and developed by ­Dennis Ritchie at
Bell Laboratories, USA, in 1972. Several important ­concepts of C C
are drawn from ‘Basic combined programming language’ and ‘B’
­language. Figure 1.6 shows the development of C ­language from the Figure 1.6 Evolution of C
two languages. Martin Richards developed BCPL in 1967. The impact
of BCPL on C is observed indirectly through the language B, which
was developed by Ken Thompson in 1970. C is also called an offspring of the BCPL. Table 1.1
illustrates the evolution of languages and their inventors of programming language.

Table 1.1 Languages and their inventors


Sr. No. Language Inventor Year
1. BCPL Martin Richards 1967
2. B Ken Thompson 1970
3. C Dennis Ritchie 1972

The C language is not tied to any particular


o­ perating system. It can be used to develop new UNIX MS-DOS
­operating systems. Refer to Figure 1.7 in which the
C language is shown associated with the various
­operating systems. The C language is closely associat-
ed with the UNIX operating system. The source code WINDOWS
C OTHER
for the UNIX operating system is in C. C runs under OS......
a number of operating systems including MS-DOS.
The C programs are efficient, fast and highly ­portable, Figure 1.7 C and operating systems
i.e. C programs written on one computer can be run on
another with mere or almost no modification.
The C programming language contains modules called functions. The C functions are the basic
building blocks and the most programmers take its benefit. Programmers include these functions in
their program from the C standard library.
C language is a middle-level computer language. It does not mean that C is not powerful and
rugged for writing programs like in Fortran and Pascal. It also does not mean that it is troublesome
like assembly level languages. It combines the features of a high-level language and functionality like
assembly languages. In C, one can develop a program fast and execute fast. It reduces the gap between
high- and low-level languages; that is why it is known as a middle level language. It is well suited for
writing both application and system softwares.
C is a structural language. It has many similarities with the other structural languages such as
Pascal and Fortran. Structured language facilitates the development of a variety of programs in small
modules or blocks. Lengthy programs can be divided into shorter programs. The user requires think-
ing of a problem in terms of functional blocks. With appropriate collection of different modules, the
programmer can make a complete program.
It is easy for writing, testing, debugging and maintenance with structured programming. In case
some changes are to be done in a program, the programmer can refer to the earlier written module
with editor and incorporate the appropriate changes. Hence, structured languages are easier and most
of the developers prefer these languages, than the non-structured languages like BASIC and COBOL.
Programming with non-structured languages is tough in comparison to structured languages.

M01_KAMT3553_02_SE_C01.indd 6 5/17/2015 9:04:19 AM


Basics and Introduction to C 7

C is also called a system-programming language because it is greatly helpful for writing operat-
ing systems, interpreters, editors, compilers, database programs and network drivers.
BCPL and B are data type-less languages. However, C language has a variety of data types. The
standard data types in C are integers, floating point, characters. Also, derived data types can be cre-
ated such as pointers, arrays, structures and unions. Expressions are built from operands and opera-
tors. Any expression or an assignment or a call to function can be a statement. The pointers provide
machine-independent address arithmetic.
C also provides control-flow statements such as decision-making statements (if–else)
and (switch-case) multi-choice statement. C supports for, while and do-while looping
statements.
C does not have any operator to perform operation on composite object. There does not exist any
function or operator that handles entire array or string. For example, to assign elements of one array
to another array simply with single assignment statement is not enough, but an element-to-element
assignment is to be done. However, structure objects can be copied as a unit.
C is not a strongly typed language. But typed statements are checked thoroughly by C compilers.
The compiler will issue errors and warning messages when syntax rules are violated. There is no au-
tomatic conversion of incompatible data types. A programmer has to perform explicit type conversion.
UNIX: The UNIX is an interactive operating system. It is useful in microcomputers, minicomputers
and main frame computers. This operating system is very portable and supports multi-user process-
ing, multi-tasking and networking. Several users can use UNIX at once for performing the same task.
This operating system was developed to connect various machines together. UNIX is primarily used
for workstations and minicomputers.

1.5 About ANSI C Standard


For many years, there was no standard version of C language, and the definition provided in reference
manual was followed. Due to this reason portability feature of C language was not provided from one
computer to another. To overcome this discrepancy, a committee was set up in the summer of 1983 to
create a standard C version which is popularly known as American National Standard Institute (ANSI)
standard.
This committee had defined once and for all a standard C language. The standardization process
took about six years for defining the C language. The ANSI C standard was adopted in 1989, and its
first copy of C language was introduced in the market in 1990.
Thus, ANSI C is internationally recognized as a standard C language. The purpose of this stan-
dard is to enhance the portability and efficient execution of C language programs on different com-
puters. Today, all compilers of C support the ANSI standard. In other words, almost all C compilers
available in the market have been designed to follow ANSI C standard. ANSI C and other C compilers
such as turbo-C version 2 support programs developed in this book.

1.6 Machine, Assembly and High-Level Language


It is a computer’s natural language, which can be directly understood by the system. This language
is machine dependent, i.e. it is not portable. A program written in 1’s and 0’s is called a machine
language. A binary code is used in a machine language for a specific operation. A set of instructions
in binary pattern is associated with each computer. It is difficult to communicate with a computer in
terms of 1s and 0s. Hence, writing a program with a machine language is very difficult. Moreover,
speed of writing, testing and debugging is very slow in machine language. Chances of making careless
errors are bound to be there in this language. The machine language is defined by the hardware design
of that hardware platform. Machine languages are tedious and time consuming.

M01_KAMT3553_02_SE_C01.indd 7 5/17/2015 9:04:19 AM


8 Programming in C

1.6.1 | Assembly Language


Instead of using a string of binary bits in a machine language, programmers started using English-
like words as commands that can be easily interpreted by programmers. In other words, the computer
manufacturers started providing English-like words abbreviated as mnemonics that are similar to
binary instructions in machine languages. The program is in alphanumeric symbols instead of 1s and
0s. The designer chooses easy symbols that are to be remembered by the programmer, so that the
programmer can easily develop the program in assembly language. The alphanumeric symbols are
called mnemonics in the assembly language. The ADD, SUB, MUL, DIV, RLC and RAL are some
symbols called mnemonics.
The programs written in other than the machine language need to be converted to the machine
language. Translators are needed for conversion from one language to another. Assemblers are used
to convert assembly language program to machine language. Every processor has its own assembly
language. For example, 8085 CPU has its own assembly language. CPUs such as 8086, 80186, 80286
have their own assembly languages.
Following disadvantages are observed with the assembly languages:
(i) It is time consuming for an assembler to write and then test the program.
(ii) Assembly language programs are not portable.
(iii) It is necessary to remember the registers of CPU and mnemonic instructions by the
programmer.
(iv) Several mnemonic instructions are needed to write in assembly language than a single line
in high-level language. Thus, assembly language programs are longer than the high language
programs.

1.6.2 | High-Level Language


Procedure-oriented languages are high-level languages. These languages are employed for easy and
speedy development of a program. The disadvantages observed with assembly languages are over-
come by high-level languages. The programmer does not need to remember the architecture and reg-
isters of a CPU for developing a program. The compilers are used to translate high-level language
program to machine language. Examples of HLL are COBOL, FORTRAN, BASIC, C and C++. The
following advantages are observed with HLL languages:
(i) Fast program development.
(ii) Testing and debugging a program is easier than in the assembly language.
(iii) Portability of a program from one machine to other.

1.7 Assembler, Compiler and Interpreter


A program is a set of instructions for performing a particular task. These instructions are just like
English words. The computer interprets the instructions as 1’s and 0’s. A program can be written in
assembly language as well as in high-level language. This written program is called the source pro-
gram. The source program is to be converted to the machine language, which is called an object pro-
gram. A translator is required for such a translation.
Program translator translates source code of programming language into machine language-
instruction code. Generally, computer programs are written in languages like COBOL, C, BASIC
and ASSEMBLY LANGUAGE, which should be translated into machine language before execution.

M01_KAMT3553_02_SE_C01.indd 8 5/17/2015 9:04:19 AM


Basics and Introduction to C 9

Programming language translators are classified as


Translator
follows. A list of translators is given in Figure 1.8.
Translators are as follows:
(i) Assembler
(ii) Compiler Assembler Compiler Interpreter
(iii) Interpreter
Figure 1.8 Translators
Assembler: An assembler translates the symbolic
codes of programs of an assembly language into
machine language instructions (Figure 1.9). The symbolic language is translated to the machine code
in the ratio of one is to one symbolic instructions to one machine code instructions. Such types of

Mnemonic Machine
Assembler
language codes

Figure 1.9 Assembler

languages are called low-level languages. The assembler programs translate the low-level language
to the machine code. The translation job is performed either manually or with a program called as-
sembler. In hand assembly, the programmer uses the set of instructions supplied by the manufacturer.
In this case, the hexadecimal code for the mnemonic instruction is searched from the code sheet. This
procedure is tedious and time-consuming. Alternate solution to this is the use of assemblers. The pro-
gram called assembler provides the codes of the mnemonics. This process is fast and facilitates the
user in developing the program speedily.
Compiler: Compilers are the translators, which
translate all the instructions of the program into Mnemonic Compilers and Machine
language interpreters codes
machine codes, which can be used again and
again (see Figure 1.10). The program, which is
to be translated, is called the source program Figure 1.10 Compiler/interpreter
and after translation the object code is gener-
ated. The source program is input to the compiler. The object code is output for the secondary storage
device. The entire program will be read by the compiler first and generates the object code. However,
in interpreter each line is executed and object code is provided. M-BASIC is an example of an inter-
preter. High-level languages such as C, C++ and Java compilers are employed. The compiler displays
the list of errors and warnings for the statements violating the syntax rules of the language. Compilers
also have the ability of linking subroutines of the program.
Interpreter: Interpreters also come in the group of translators. It helps the user to execute the source
program with a few differences as compared to compilers. The source program is just like English
statements in both interpreters and compilers. The interpreter generates object codes for the source
program. Interpreter reads the program line by line, whereas in compiler the entire program is read by
the compiler, which then generates the object codes. Interpreter directly executes the program from
its source code. Due to this, every time the source code should be inputted to the interpreter. In other
words, each line is converted into the object codes. It takes very less time for execution because no
intermediate object code is generated.

M01_KAMT3553_02_SE_C01.indd 9 5/17/2015 9:04:20 AM


10 Programming in C

Linking: C language provides a very large library, which contains numerous functions. In some
applications of C the library may be a very large file. Linker is a program that combines source
code and codes from the library. Linking is the process of bringing together source program and
library code.
The library functions are relocatable. The addresses of various machine codes are defined abso-
lutely and only the offset information is kept. When the source program links with the standard library
functions, offset of the memory addresses is used to create the actual address.

1.8 Structure of a C Program


Every C program contains a number of building blocks known as functions. Each function of
it performs a specific task independently. A C program comprises different sections shown in
Figure 1.11.
(i) Include Header File Section: C program
d­ epends upon some header files for function
definition that are used in the program. Each Include header file
header file has extension ‘.h’. The ­header Global Declaration
files are included at the beginning of the /* comments */
­program in the C language. These files should /*Function name */
be included using # include directive as given main ()
below.
­
{
/* comments */
Example:
Declaration part
# include <stdio.h> or Executable part
# ­
include “stdio.h” Function call
In this example, <stdio.h> file is ­included,
i.e. all the definitions and prototypes of function }
defined in this file are available in the current
program. This file is also compiled with the orig- User-defined functions
inal program. The programmer can include the
appropriate header files while executing solved
Figure 1.11 Structure of a C program
or unsolved programming examples given in this
book.
(ii) Global Declaration: This section declares some variables that are used in more than one func-
tion. These variables are known as global variables. This section must be declared outside of
all the functions.
(iii) Function main(): Every program written in C must contain main() and its execution starts
at the beginning of this function. In ASCII C standard, first line of C program from where
program execution begins is written as follows.
int main(void)
This is the function definition for main(). Parenthesis followed to main is to tell the user
again that main() is a function. The int main(void) is a function that takes no argu-
ments and returns a value of type int. Here in this line, int and void are keywords and they
have special meanings assigned by the compiler. In case int is not mentioned in the above
statement, by default the function returns an integer.

M01_KAMT3553_02_SE_C01.indd 10 5/18/2015 12:14:34 PM


Basics and Introduction to C 11

Alternately, one can also write the first line of C program from where program execution be-
gins is as follows.
void main(void)
Here, this function takes no arguments and returns nothing. Alternately, one can also write the
same function as follows.
void main(): This functions returns nothing and takes no arguments.
In all chapters, in maximum programming examples the main function is written as void
main(). This procedure is followed in this book only to avoid writing return statement at
the end of each program. This step helps to minimize source code lines. At few places in this
book, main function is initialized with int main(void). In such a case, return state-
ment is used at the end of program (before closing brace). The programmer can either write
the function main with int main(void) or void main(). Only in the formal case,
return statement should be used before the end of function for terminating the execution of
the main function.
The program contains statements that are enclosed within the braces. The opening brace ({)
and closing brace (}) are used in C. Between these two braces, the program should declare
declaration and executable part. The opening curly brace specifies the start of the definition of
the main function. The closing curly brace specifies the end of the code for the main function.
(iv) Declaration Part: The declaration part declares the entire local variables that are used in
executable part. Local variable scope is limited to that function where the local variables are
­declared. The initializations of variables can also be done in this section. The initialization
means providing initial value to the variables.
(v) Executable Part: This part contains the statements following the declaration of the variables.
This part contains a set of statements or a single statement.
(vi) Function Call: From the main() a user defined function can be invoked by the user as per
need/application.
(vii) User-defined Function: The functions defined by the user are called user-defined functions.
These functions are defined outside the main() function.
(viii) Body of the Function: The statements enclosed within the body of the function (between
opening and closing brace) are called body of the function.
(ix) Comments: Comments are not necessary in a program. However, to understand the flow of
programs a programmer can insert comments in the program. Comments are to be inserted by
the programmer. It is useful for documentation. The clarity of the program can be followed if
it is properly documented.
Comments are statements that give us information about the program which are to be placed
between the delimiters /* and */. The programmers in the programs for enhancing the
lucidity frequently use comments. The compiler does not execute comments. Thus, we can say
that comments are not a part of executable programs.
A user can frequently use any number of comments that can be placed anywhere in a
program. Please note that comment statements can be nested. The user should select the
OPTION MENU of the editor and select the COMPILER-SOURCE - NESTED COMMENTS
ON/OFF. The comments can be inserted with single statement or in nested statements.

M01_KAMT3553_02_SE_C01.indd 11 5/17/2015 9:04:20 AM


12 Programming in C

Example:
/* This is single comment */
/* This is an example of /* nested comments */*/
/* This is an example of
of comments in
   multiple lines */ /* It can be nested */

1.9 Programming Rules
A programmer while writing a program should follow the following rules:
(i) Every program should have main() function.
(ii) C statements should be terminated by a semi-colon. At some places, a comma operator is per-
mitted. If only a semi-colon is placed it is treated as a statement. For example:
while(condition)
;
The above statement generates infinite loop. Without semi-colon the loop will not execute.
(iii) An unessential semi-colon if placed by the programmer is treated as an empty statement.
(iv) All statements should be written in lowercase letters. Generally, uppercase letters are used
only for symbolic constants.
(v) Blank spaces may be inserted between the words. This leads to improvement in the readability
of the statements. However, this is not applicable while declaring a variable, keyword, constant
and function.
(vi) It is not necessary to fix the position of statement in the program; i.e. a programmer can write
the statement anywhere between the two braces following the declaration part. The user can
also write one or more statements in one line separating them with a semi-colon (;). Hence, it
is often called a free-form language. The following statements are valid:
a=b+c;
d=b*c;
or
a=b+c; d=b*c;
(vii) The opening and closing braces should be balanced, i.e. if opening braces are four; closing
braces should also be four.

1.10 Executing the C Program


A C program must go through various phases such as creating a program with editor, execution of
preprocessor program, compilation, linking, loading and executing the program. The following steps
are essential in C when a program is to be executed in MS-DOS mode:
(i) Creation of a Program: The program should be written in C editor. The file name does not
necessarily include extension ‘.C’. The default extension is ‘.C’. The user can also specify
his/her own extension. The C program includes preprocessor directives.
(ii) Execution of a Preprocessor Program: After writing a program with C editor the program-
mer has to compile the program with the command (Alt-C). The preprocessor program executes

M01_KAMT3553_02_SE_C01.indd 12 5/17/2015 9:04:20 AM


Basics and Introduction to C 13

first automatically before the compilation of the program. A programmer can include other files
in the current file. Inclusion of other files is done initially in the preprocessor section.
(iii) Compilation and Linking of a Program: The source program contains statements that are to be
translated into object codes. These object codes are suitable for execution by the computer. If a
program contains errors the programmer should correct them. If there is no error in the program,
compilation proceeds and translated program is stored in another file with the same file name with
extension ‘.obj’. This object file is stored on the secondary storage device such as a disc.
Linking is also an essential process. It puts together all other program files and functions that
are required by the program. For example, if the programmer is using pow() function, then
the object code of this function should be brought from math.h library of the system and
linked to the main() program. After linking, the program is stored on the disc.
(iv) Executing the Program: After the compilation the executable object code will be loaded in the
computer’s main memory and the program is executed. The loader performs this function. All the
above steps/phases of C program can be performed using menu options of the editor.
As shown in Figure 1.12, pre-processor directories/program is executed before compilation
of the main program. The compiler checks the program and if any syntax error is found, the same

Source program editor

Pre-processor

Compile source program

Is syntax
error? Yes

No

System library Linking process

Input again Execute object code

Input error Is logic and data Logic error


Yes error? Yes

No
Run time error Compile time error

Output

Figure 1.12 Flow chart of a program in C

M01_KAMT3553_02_SE_C01.indd 13 5/17/2015 9:04:21 AM


14 Programming in C

is displayed. The user is again forced to go to edit window. After removing an error, the compiler
compiles the program. Here, at this stage object code is generated. During the program execution, if
user makes mistakes in inputting data, the result would not be appropriate. Therefore, the user again
has to enter the data. The output is generated when a program is error free.
Editing, compiling and executing a program file with an editor (Figure 1.13):

Figure 1.13 Window to Turbo C editor

The programmer can use the Turbo C editor/compiler. The Turbo C editor is a software, in which the
programmer can write the program in C source code. The window to Turbo C editor appears when we
invoke shortcut to TC icon, which can be placed on desktop. This window is used for editing, compil-
ing and running the program.
Its menu bar comprises eight menus: File, Edit, Run, Compile, Project, Options, Debug and
Break/watch.
File: This menu is used for creating a new program file, loading an existing C file, writing the file
with appropriate path, invoking DOS (OS Shell), changing directory and quitting the program.
Edit: The Edit menu provides editing options.
Run: The Run menu provides options such as Run, Program reset, Go to cursor, Trace into, Step
over and User screen.
On pressing Alt+F keys, one can go to the File menu and select either New for creating a new
file or in case file is already existing then use Load option and load the file by giving the appropriate
path. Extension of the file with .c is automatically provided by the editor. The programmer can put
extension .c or by default .c is provided by the editor. The programmer can now write a program with
C syntax.
It is better to create and save programs in a separate folder/subdirectory in the home directory of
the disk. The folder/subdirectory is the working directory. This is due to the association of the program
file with several files created during compiling and running. Files created are your own files (source
code file and data files) and besides, some other files created are after compilation and running the
program.
For example if C:\Turboc2 is home directory, a subdirectory can be created with the ­Command
prompt. Assume that the created subdirectory is Vishal, then working directory path would be
C:\Turboc2\Vishal. So, create and save all programs in the working directory Vishal (Figure 1.14).

M01_KAMT3553_02_SE_C01.indd 14 5/17/2015 9:04:21 AM


Basics and Introduction to C 15

Figure 1.14 Opening a new file

After editing the program file, the same should be saved either with F2 key or Alt+F & Save from File
menu and compiled from compile menu. Now programmer can use the keys Alt+C in the editor as shown
below (Figure 1.15).

Figure 1.15 Compilation of program


On compilation, the same program is to be run with Alt+R keys. The screen appears as shown below. Of
course, this step is adapted when there are no errors after compilation. After running the program, ­answer
appears on the other screen. The programmer can try a simple program as cited below in the window.
­Executable file is created after running the program file. The .exe file created can be observed (Figure 1.16).

Figure 1.16 Running a program


It is expected to edit, compile and run a program given in the above snapshot by the user in the C editor.

M01_KAMT3553_02_SE_C01.indd 15 5/17/2015 9:04:22 AM


16 Programming in C

1.11 Standard Directories
The turbo-C has three standard directories; they are include, sys and lib. The Sys is the
sub-directory of include. The include directory contains all the header files and lib con-
tains all the library files. Before executing the program the path setting should be done. In turbo-
c edit, select Option menu Directories option. Here, set the path of include, library and
turbo-c-directories.

1.12 The first C program


1.1 Write a program to display message “Hello! C Programmers”.

void main()
{
printf(“Hello! C Programmers”);
}
OUTPUT:
Hello! C Programmers

Explanation:
This program displays the message ‘Hello! C Programmers’ using the printf()
statement. Follow the following steps to execute the program through Turbo-c editor.
After typing a program by pressing F2, a program can be saved. If you are saving for the first
time, a name will be asked. Type the file and the extension (.c) will automatically be added.
By pressing ALT+C you can reach the compile option. Also by pressing F9, you can compile
the program. To execute the program you can press CTRL + F9. To see the output of the
program, press ALT+F5. User can make exe file by pressing F9 key twice.
1.2 Write a program to know about the use of comments (how to use comments?).

void main()
{
clrscr(); /* clears the screen */
printf(“\This program explains comments”);
/* How to use comment? */
}
OUTPUT:
This program explains comments

Explanation:
In the above program, we can observe how comments are inserted in a program. The
comments are not an executable part. It is only useful for the programmer to understand
the flow of a program. This program prints the message as shown in the output.
The function clrscr() clears the screen, defined in header file <conio.h>.
Although the file is not included, some compilers allow execution and some will flag
an error message.

M01_KAMT3553_02_SE_C01.indd 16 5/17/2015 9:04:22 AM


Basics and Introduction to C 17

1.3 Write a program to return the value from main().

main()
{
return 0;
}

Explanation:
The above program produces no output. The main() should return a value of either 0 or 1.
Some operating systems check the return value of main(). If main() returns 0, i.e. pro-
gram executed successfully; else for other value OS assumes the opposite. If user fails to put
the return statement, the compiler would not complain.

1.13 Advantages of C
(i) It contains a powerful data definition. The data type supported are characters, alphanumeric,
integers, long integer, floats and double. It also supports string manipulation in the form of
character array.
(ii) C supports a powerful set of operators.
(iii) It also supports powerful graphics programming and directly operates with hardware. Execu-
tion of program is faster.
(iv) An assembly code is also inserted into C programs.
(v) C programs are highly portable on any type of OS platforms.
(vi) System programs such as compilers, operating systems can be developed in C. For example,
the popular operating system UNIX is developed in C.
(vii) The C language has 32 keywords and about 145 library functions and near about 30 header
files.
(viii) C works closely with machines and matches assembly language in many ways.

1.14 Header Files
stdio.h: Standard input and output files. All formatted and unformatted functions include file
operation functions defined in this file. The most useful formatted printf() and scanf() are
defined in this file. This file must be included at the top of the program. Most useful functions from
this header files are printf(), scanf(), getchar(), gets(), putc() and putchar().
conio.h: Console input and output. This file contains input and output functions along with a few
graphic-supporting functions. The getch(), getche() and clrscr() functions are defined in
this file.
math.h: This file contains all mathematical and other useful functions. The commonly useful func-
tions from this files are floor(), abs(), ceil(), pow(), sin(), cos() and tan(). The list
of commonly used header files are given in Table 1.2

M01_KAMT3553_02_SE_C01.indd 17 5/17/2015 9:04:22 AM


18 Programming in C

Table 1.2 Commonly useful header files


Sr. No. Header File Functions Function Examples
1. stdio.h Input, output and file operation functions printf(), scanf()
2. conio.h Console input and output functions clrscr(), getche()
3. alloc.h Memory allocation-related functions malloc(), realloc()
4. graphics.h All graphic-related functions circle(), bar3d()
5. math.h Mathematical functions abs(), sqrt()
6. string.h String manipulation functions strcpy(), strcat()
7. bios.h BIOS accessing functions biosdisk()
8. assert.h Contains macros and definitions void assert(int)
9. ctype.h Contains prototype of functions which test isalpha(char)
characters
10. time.h Contains date- and time-related functions asctime()

There are different ways of representing the logical steps for finding a solution of a given problem.
They are as follows:
(i) Algorithm
(ii) Flowchart
(iii) Pseudo-code
In the algorithm, a description of the steps for solving a given problem is provided. Here, stress is given on the
text. Flowchart represents the solution of a given problem graphically. Pictorial representation of the logical
steps is a flowchart. Another way to express the solution of a given problem is by means of a pseudo-code.

1.15 Algorithm
Algorithm is a very popular technique used to obtain a solution for a given problem. The algorithm
is defined as ‘the finite set of steps, which provide a chain of actions for solving a definite nature of
problem’. Each step in the algorithm should be well defined. This step will enable the reader to trans-
late each step into a program. Gradual procedure for solving a problem is illustrated in this section.
An algorithm is a well-organized, pre-arranged and defined textual computational module that
receives some value or set of values as input and provides a single value or a set of values as output.
These well-defined computational steps are arranged in a sequence, which processes the given input
into an output. Writing precise description of the algorithm using an easy language is most essential
for understanding the algorithm. An algorithm is said to be accurate and truthful only when it provides
the exact required output. Lengthy procedure is sub-divided into small parts and thus steps are made
easy to solve a given problem. Every step is known as an instruction.
In our daily life, we come across numerous algorithms for solving problems. We perform several
routine tasks, for example riding a bike, lifting a phone, making a telephone call, switching on a televi-
sion set and so on.
For example, to establish a telephonic communication between two subscribers, following steps
are to be followed:
(i) Dial a phone number
(ii) Phone rings at the called party
(iii) Caller waits for the response
(iv) Called party picks up the phone

M01_KAMT3553_02_SE_C01.indd 18 5/17/2015 9:04:22 AM


Basics and Introduction to C 19

(v) Conversation begins between them


(vi) After the conversation, both disconnect the call
Another real life example is to access Internet through Internet service provider with dial up facility.
To log on to the Internet, the following steps are to be followed:
(i) Choose the Internet service provider for accessing the Internet.
(ii) Obtain from service provider a dial up number.
(iii) Acquire IP address of the service provider.
(iv) Acquire login ID and password.
(v) Run the Internet browsing software.
When one writes an algorithm, it is essential to know how to analyse the algorithm. Analysing al-
gorithm refers to calculating or guessing resources needed for an algorithm. Resources mean com-
puter memory, processing time, logic gates. In all the above factors, time is the most important factor
because the program developed should be faster in processing. The analysis can also be made by
reading the algorithm for logical accuracy, tracing the algorithm, implementing it, and checking with
some data and with mathematical techniques to confirm its accuracy.
Algorithms can also be expressed in a simple method. It will help the user to put into operation
easily. However, this approach has a few drawbacks. It requires more space and time. It is very essen-
tial to consider the factors such as time and space of an algorithm. With minimum resources of system
such as CPU’s time and memory, an efficient algorithm must be developed.
Practically, it is not possible to do a simple analysis of an algorithm to conclude the execution time of an
algorithm. The execution time is dependent upon the machine and the way of implementation. The timing
analysis depends upon the input required. To accurately carry out the time analysis, it is also very essential
to know the exact directives executed by the hardware and the execution time passed for each statement.
1.4 Write a program to swap two numbers using a third variable.
Flowchart for swapping
Algorithm for swapping two numbers:
two numbers:
STEP 1: Start.
STEP 2: Declare variables a, b, & c. START
STEP 3: Read values of a & b.
STEP 4: Copy value of a to c; b to a; & c to b.
Declare variables a, b, c.
STEP 5: Print swapped values of a & b.
STEP 6: Exit.
Program:
Enter the values of
void main()
a&b
{
   int a,b,c;
   clrscr();
c = a;
    printf(“\nEnter two numbers for A & B:”); a = b;
   scanf(“%d %d”,&a,&b); b = c;
   c=a;
   a=b;
   b=c;
Print a, b
   printf(“\nAfter swaping the values
are:A=%d & B=%d.”,a,b);
   getch();
END
}

M01_KAMT3553_02_SE_C01.indd 19 5/17/2015 9:04:23 AM


20 Programming in C

Hint: Copy value of a in third variable c, value of b in a, and value of c in b.


Explanation:
In the above cited program, first three variables a, b, & c are declared. The program invokes
two values of a & b from user. The user assigns values to the variables a & b.
Now copy the value of a in third variable c, value of b in a, and value of c in b.
Here, when we assign the value of a to c (c = a), the value of a is copied in variable c. When we
assign (a = b), the value of b is copied in variable a and the previous value is replaced. Now,
b holds the value of variable c in statement (b = c).
The printf( ) statement prints the values of a & b.
1.5 Write a program to swap two numbers without using a third variable.

Algorithm: Flowchart:
STEP 1: Start.
STEP 2: Declare two variables a & b. START
STEP 3: Addition of a & b and place result in a.
STEP 4: Subtraction of a & b and place result in b.
STEP 5: Subtraction of a & b and place result in a. Declare variables &
assign values to a & b.
STEP 6: Print values of a & b.
STEP 7: End.
Program: a = a + b;
void main() b = a − b;
{ a = a − b;
   int a=4,b=6;
   clrscr();
   a=a+b;
   b=a-b; Print values
   a=a-b; of a & b
    printf(“\nthe value of a=%d & b=%d”,a,b);
   getch();
} END
OUTPUT:
The value of a=6 & b=4

Explanation:
In the above cited program, first two variables a & b are declared and initialized.
Values of a & b are added in the statement a = a + b. In the next statement, b is subtracted from
a and result is stored in b. Finally, the value of a is obtained by subtracting b from a.
The printf( ) statement prints the values of a & b.

1.15.1 | Program Design


When you have thoroughly studied the program and examined the requirement of the program, the
next step is to design the program. To make the programs simple, divide the program into smaller
modules. This makes thinking process easy and you can separately apply logic on each portion. After
dividing the program, according to priority and importance write the code.

M01_KAMT3553_02_SE_C01.indd 20 5/17/2015 9:04:23 AM


Basics and Introduction to C 21

Coding Programs: Coding a program is the second step. Once you have understood the program,
now you can implement through the code. If a program is short, start coding from the beginning to
top in a sequence. Identify the different variables and selection or control structures required. Also
write comments so that you can follow them in future. While coding, appropriate messages for user’s
direction should be prompted.
Testing Programs: After completing the coding of a program, the next step is to test the program.
Confirm that the required source files and data files are at the specified location in the system.

1.16 Classification of Algorithms


The classification of algorithm is based on repetitive steps and on control transfer from one statement
to another. Figure 1.17 shows the classification of Algorithms.

Algorithms

Based on repetitive Based on control


steps transfer

Direct Indirect Deterministic Non-deterministic Random

Figure 1.17 Classifications of algorithms

On the basis of repetitive steps, an algorithm can further be classified into two types.
(i) Direct Algorithm: In this type of algorithm, the number of iterations is known in advance.
For example, for displaying numerical numbers from 1 to 10, the loop variable should be ini-
tialized from 1 to 10. The statement would be as follows:
for (j=1;j<=10;j++)
In the above statement, it is predicted that the loop will iterate 10 times.
(ii) Indirect Algorithm: In this type of algorithm, repetitively steps are executed. Exactly how
many repetitions are to be made is unknown.
For example, the repetitive steps are as follows:
  (i) T o find the first five Armstrong numbers from 1 to n, where n is the fifth Armstrong
­number.
  (ii) To find the first three palindrome numbers.

M01_KAMT3553_02_SE_C01.indd 21 5/17/2015 9:04:24 AM


22 Programming in C

Based on the control transfer, the algorithms are categorized in the following three types.
(i) Deterministic: Deterministic algorithm is based on either to follow a ‘yes’ path or ‘no’ path
based on the condition. In this type of algorithm when control comes across a decision logic,
two paths ‘yes and ‘no’ are shown. Program control follows one of the routes depending upon
the condition.
Example:
Testing whether a number is even or odd. Testing whether a number is positive or negative.
Non-deterministic: In this type of algorithm to reach to the solution, we have one of the mul-
(ii)
tiple paths.
Example:
To find a day of a week.
Random algorithm: After executing a few steps, the control of the program transfers to
(iii)
another step randomly, which is known as a random algorithm.
Example:
A random search
Another kind of an algorithm is the infinite algorithm.
Infinite algorithms: This algorithm is based on better estimates of the results. The number
of steps required would not be known in advance. The process will be continued until the best
results emerged. For final convergence more iterations would be required.
Example:
To find shortest paths from a given source to all destinations in the network.

1.17 FLOWCHARTS
A flowchart is a visual representation of the sequence of steps for solving a problem. It enlightens
what comes first, second, third, and so on. A completed flowchart enables you to organize your prob-
lem into a plan of actions. Even for designing a product a designer many times has to draw a flowchart.
It is a working map of the final product. This is an easy way to solve the complex designing problems.
The reader follows the process quickly from the flowchart instead of going through the text.
A flowchart is an alternative technique for solving a problem. Instead of descriptive steps, we use
pictorial representation for every step. It shows a sequence of operations. A flowchart is a set of symbols,
which indicates various operations in the program. For every process, there is a corresponding symbol
in the flowchart. Once an algorithm is written, its pictorial representation can be done using flowchart
symbols. In other words, a pictorial representation of a textual algorithm is done using a flowchart.
We give below some commonly used symbols in flowcharts.
Start and end: The start and end symbols indicate both the beginning and the end of the flowchart.
This symbol looks like a flat oval or is egg shaped. Figure 1.18 shows the symbol of Start/stop. Only
one flow line is combined with this kind of symbol. We write START, STOP or END in the symbols
of this kind. Usually this symbol is used twice in a flowchart, that is, at the beginning and at the end.

Start

Stop

Figure 1.18 Start/stop symbol

M01_KAMT3553_02_SE_C01.indd 22 5/17/2015 9:04:24 AM


Basics and Introduction to C 23

Decision or test symbol: The decision symbol is diamond shaped. This symbol is used to take one
of the decisions. Depending on the condition the decision block selects one of the alternatives. While
solving a problem, one can take a single, two or multiple alternatives depending upon the situation. All
these alternatives are illustrated in this section. A decision symbol with a single alternative is shown in
Figure 1.18. In case the condition is satisfied /TRUE a set of statement(s) will be executed otherwise
for false the control transfers to exit.
Single alternative decision: Here more than one flow line can be used depending upon the condi-
tion. It is usually in the form of a ‘yes’ or ‘no’ question, with branching flow line depending upon the
answer. With a single alternative, the flow diagram will be as per Figure 1.19.

Entry

Condition?

True False

Execution of statement(s)

Exit

Figure 1.19 Single alternative decision

Two alternative decisions: In Figure 1.20 two alternative paths have been shown. On satisfying the
condition statement(s) pertaining to 1 action will be executed, otherwise the other statement(s) for
action 2 will be executed.

Entry

Condition?

True False

Execution of action 1 Execution of action 2

Exit

Figure 1.20 Two alternative decisions

Multiple alternative decisions: In Figure 1.21 multiple decision blocks are shown. Every decision
block has two branches. In case the condition is satisfied, execution of statements of appropriate
blocks take place, otherwise next condition will be verified. If condition 1 is satisfied then block 1
statements are executed. In the same way, other decision blocks are executed.

M01_KAMT3553_02_SE_C01.indd 23 5/17/2015 9:04:24 AM


24 Programming in C

Entry

True
Condition 1 Execution of block 1

False

True
Condition 2 Execution of block 2

False

True
Condition 3 Execution of block 3

False

Exit

Figure 1.21 Multiple alternative decisions

Connector symbol: A connector symbol has to be shown in the form of a circle. It is used to establish
the connection, whenever it is impossible to directly join two parts in a flowchart. Quite often, two
parts of the flowcharts may be on two separate pages. In such a case, connector can be used for joining
the two parts. Only one flow line is shown with the symbol. Only connector names are written inside
the symbol, that is, alphabets or numbers. Figure 1.22 shows the connector symbol.

Connector for connecting Connector that comes from the


to the next block previous block

Figure 1.22 Connector symbol

Process symbol: The symbol of process block should be shown by a rectangle. It is usually used for
data handling, and values are assigned to the variables in this symbol. Figure 1.23 shows the process
symbol. The operations mentioned within the rectangular block will be executed when this kind of
block is entered in the flowchart. Sometimes an arrow can be used to assign the value of a variable to
another. The value indicated at its head is replaced by the tail values. There are two flow lines con-
nected with the process symbol. One line is incoming and the other line goes out.

Z=X+Y
P=X*Y

Figure 1.23 Process symbol

M01_KAMT3553_02_SE_C01.indd 24 5/17/2015 9:04:25 AM


Basics and Introduction to C 25

Loop symbol: This symbol looks like a hexagon. This symbol is used for implementation of for
loops only. Four flow lines are associated with this symbol. Two lines are used to indicate the
sequence of the program and remaining two are used to show the looping area, that is, from the
beginning to the end.
For the sake of understanding, Figure 1.24. illustrates the working of for loop. The variable J is
initialized to 0 and it is to be incremented by a step of 2 until it reaches the final value 10. For every
increased value of J, body of the loop is executed. This process will be continued until the value of J
reaches 10. Here the next block is shown for the repetitive operation.

Entry

For J = 0 to 10 by
step 2

Body of the
for loop

To continue the
for loop

Exit

Figure 1.24 For loop

Input/output symbol: Input/output symbol looks like a parallelogram, as shown in Figure 1.25. The
input/output symbol is used to input and output the data. When the data is provided to the program for
processing, then this symbol is used. There are two flow lines connected with the input/output symbol.
One line comes to this symbol and the other line goes from this symbol.
As per Figure 1.25 compiler reads the values of X, Y and in the second figure the result is dis-
played on the monitor or the printer.

Read X, Y Print X, Y

Figure 1.25 Input/output symbol

Figure 1.26 Delay symbol

Delay symbol: Symbol of delay is just like ‘AND’ gate. It is used for adding delay to the process. It is
associated with two lines. One is incoming and the other is outgoing, as shown in Figure 1.26.

M01_KAMT3553_02_SE_C01.indd 25 5/17/2015 9:04:26 AM


26 Programming in C

Figure 1.27 Manual input symbol

Manual input symbol: This is used for assigning the variable values through the keyboard, whereas
in data symbol the values are assigned directly without manual intervention. Figure 1.27 represents
the symbol of manual input.
In addition, the following symbols (Figure 1.28) can be used in the flowchart and they are parts
of flowcharts.

Alternate process Predefined process Internal storage

Manual operation Off-page connector Card Flow lines

Punched tape Summing junction Or Collate

Sort Extract Merge Stored data

Sequential access Display Direct access


storage storage

Figure 1.28 Some other symbols used in the flowchart

1.18 PSEUDOCODE
In pseudocodes english-like words are used to represent the various logical steps. It is a prefix repre-
sentation. Here solution of each step is described logically. The pseudocode is just the raw idea about
the problem. By using this tip, one can try to solve the problem. The meaning of pseudocode is ‘false
code.’ The syntax rule of any programming language cannot be applied to pseudocode.
Example (a): Assume a and b are two numbers and find the larger out of them. In such a case, com-
parison is made between them.

M01_KAMT3553_02_SE_C01.indd 26 5/17/2015 9:04:27 AM


Basics and Introduction to C 27

This can be represented as follows.

Algorithm Pseudocode
Input a and b. get numbers a & b
Is a>b. Compare a & b
If yes a is larger than b. if a is large max=a
If no b is larger than a. if b is large max=b
Print the larger number. Larger number is max

Few skilled programmers prefer to write pseudocode for drawing the flowchart. This is because using
pseudocode is analogous to writing the final code in the programming language. Few programmers
prefer to write the steps in algorithm. Few programmers favour flowchart to represent the logical flow
because with visualization things are clear for writing program statements. For beginners a flowchart
is a straightforward tool for writing a program.
Example (b): The example (b) illustrates how the pseudo code is used to draw the flowchart for squar-
ing a number.
(i) Accept number
(ii) Calculate square of the number
(iii) Display number
All the steps of the program are written down in steps. Some programs follow pseudocode to draw
flowcharts. Using pseudocode, final program can be written. Majority of programs have common
tasks such as input, processing and output. These are fundamental tasks of any program.
Using pseudocode a flowchart can be drawn as per the following steps.
For the statement, that is, ‘Accept number’ the flowchart symbol is as per Figure 1.29.

Accept
number

Figure 1.29 Input symbol

The statements including arithmetic operations are examples of processing statements. The repre-
sentation of second statement ‘Calculate square of the number’ can be represented as in Figure 1.30.

Calculate square
of the number

Figure 1.30 Processing symbol

The output statement, that is, ‘Display number’ can be represented as per Figure 1.31.

Display
number

Figure 1.31 Output symbol

In addition,the flowchart has two more symbols to indicate the beginning and the end of the program
as per Figure 1.32 The standard terminator symbol is racetrack.

M01_KAMT3553_02_SE_C01.indd 27 5/17/2015 9:04:28 AM


28 Programming in C

Begin

Begin
Accept
number 1. Accept number

Calculate square
of the number 2. Calculate square of
the number

Display 3. Display number


number

End End

Figure 1.32 Pseudocode and flowchart of a program

sUmmary

This chapter presents the evolution and basics of C. C is a structural language. It has many similari-
ties like other structural languages such as Pascal and Fortran. C is also called a system-programming
language. The ANSI C standard was adopted in December 1989 and the first copy of C language was
introduced in the market in 1990.
The reader is exposed to an assembler that translates the symbolic code of programs of an
assembly language into machine language instructions. Similarly, compilers are the translators, which
translate all the instructions of the program into machine codes and can be used again and again. An
interpreter comes in the group of translators. It helps the user to execute the source program with few
differences as compared to compilers.
In this chapter, an overview of algorithms was given. An algorithm is defined as ‘the finite set of
the steps, which provide a chain of actions for solving a definite nature of problem’. Algorithms are of
two types, direct algorithm and indirect algorithm.

exerCises
I True or false:
1. C Language is developed by Ken Thompson. 8. Every C Program should have the main()
function.
2. C Language was developed in the year 1972.
9. In C, all the statements should be written in small
3. C Language is closely associated with Linux.
letters only.
4. C Programs are not portable.
10. After compilation, the object file of a source pro-
5. The ANSI C standard was developed in 1989. gram is created.
6. C Programs are translated into object code by a 11. It is not possible to crate .exe file in C.
compiler.
12. Compiler executes a program even if the program
7. An interpreter reads one line at a time. contains warning messages.

M01_KAMT3553_02_SE_C01.indd 28 5/17/2015 9:04:28 AM


Basics and Introduction to C 29

13. In Turbo-C editor Alt+C is used to execute the 18. Assembler translates low-level language to ma-
program. chine code.
14. A comment can be split in more than one line. 19. The compiler reads firstly entire program and
generates the object code.
15. The source code for the UNIX operating system
is in C. 20. C does not have automatic conversion of compat-
ible variable.
16. The assembly language program is in alphanu-
meric symbols. 21. Every processor has its own assembly language.
17. Linking software is used to bring together the 22. Assembly language program is portable.
source program and library code.

II Select the appropriate option from the multiple choices given below:

1. The C language has been developed by 7. The C program should be written only in
(a) Patrick Naughton (a) lower case
(b) Dennis Ritche (b) upper case
(c) Ken Thompson (c) title case
(d) Martin Richards (d) sentence case
2. The C programming is a 8. The role of a compiler is to translate source
program statements to
(a) high-level language
(b) low-level language (a) object codes
(c) middle-level language (b) octal codes
(d) assembly language (c) decimal codes
(d) None of the above
3. The C programs are converted into machine lan-
guage using 9. The extension for C program files by default is
(a) an assembler (a) ‘.c’
(b) a compiler (b) ‘.d’
(c) an interpreter (c) ‘.obj’
(d) an operating system (d) ‘.exe’
4. The C language was developed in the year 10. The C can be used with

(a) 1972 (a) only UNIX operating system


(b) 1980 (b) only LINUX operating system
(c) 1975 (c) only MS-DOS operating system
(d) 1971 (d) All the above

5. The C language has been developed at 11. The C language is closely associated with

(a) AT & T Bell Labs, USA (a) MS-DOS


(b) IBM, USA (b) LINUX
(c) Borland International, USA (c) UNIX
(d) Sun Microsystems (d) MS-windows

6. The C language is an offspring of the 12. The C programs are highly portable means

(a) ‘BPCL’ language (a) same programs execute on different computers


(b) ‘ALGOL’ language (b) program executes only on the same computer
(c) ‘Basic’ language (c) program needs a lot of modification to run
(d) None of the above (d) None of the above

M01_KAMT3553_02_SE_C01.indd 29 5/17/2015 9:04:28 AM


Other documents randomly have
different content
"Rosvopäällikönkö?"

"Niin."

"Hän on nyt kuollut?"

"On."

"Hänet surmasi eräs ulkomaalainen kaksintaistelussa Meksikon


ylätasangolla. Minä olin siihen aikaan Meksikossa. Carranzan leirissä
puhuttiin paljon Zapatan kuolemasta. Se oli kova mies. Tahtoisinpa
puhella sen miehen kanssa, joka hänet surmasi."

"Se käy helposti päinsä."

"Kuinka niin?"

"No, mehän istumme tässä vastakkain, hän ja te. Sillä Emiliano


Zapatan surmasin minä."

Ribeira nousi hitaasti seisomaan.

"Vai niin, tekö sen teitte", hän sanoi. "Silloin en kadu, että en
laukaissut asettani teitä vasten, sillä se olisi ollut aivan liian helppo ja
hauska kuolema Emiliano Zapatan surmaajalle. Sanokaa — oletteko
kuullut puhuttavan kiehuvasta lyijystä?"

"Kyllä. Mitä tarkoitatte?"

"Ehkä teitä huvittaa joutua paroni de Nozier'n käsiteltäväksi. Hän


on nero myöskin ihmisten kiduttamisessa. Hänen olisi pitänyt olla
Tuomas Torquemadalaisen ensimäisenä apulaisena. Niin, sillä nyt te
olette käsissämme, ukkoseni. Luottakaa siihen. Kymmenen minuutin
perästä puhelemme lähemmin inkvisitsion mahdollisuuksista."
"Se on oleva teille jotakuinkin vaikeata."

"Kuinka niin?"

"Senvuoksi, että ennenkuin saatte tilaisuuden tämän


mielenkiintoisen kysymyksen pohtimiseen, olette kuollut mies."
XXXVII.

BILJARDINPELAAJA.

Kello oli juuri lyönyt neljä Pariisin suuressa biljardipalatsissa


Kapusiinien bulevardin varrella ja neljä biljardiprofessoria, joitten
juuri piti alkaa pelinsä, astuivat esiin katselijain hyväksyen
tervehtiessä. Siinä oli kuuluisa Curo, ranskalainen au cadre-mestari,
jolla oli pienoinen pyöreähkö vatsa, edelleen Gibelin,
eteläranskalainen elostelija, joka ei koskaan näyttänyt saaneen
levätä kyllikseen, ja paksu rehevä Maquet, jonka vatsa oli siihen
määrin paisunut, että hän kohta ei enää kyennyt kumartumaan
biljardipöydälle niin paljon, että olisi voinut tehdä kunnollisia
lyöntejä.

Neljäs oli useimmille tuntematon suuruus — nuori, miellyttävän


näköinen mies, jolla oli kalpeat kasvonpiirteet ja hiukan huojuvat
liikkeet.

Ennen pelin alkamista astui pelinohjaaja esiin ja piti seuraavan


puheen:
"Hyvät naiset ja herrat! Ennenkuin tänään alotamme billard
rouge'n mestaruuskilpailut, rohkenen teille esitellä erään etevän
pelaajan, joka pyytää saada ottaa osaa tähän ratkaisevaan taisteluun
Ranskan ammattimestaruudesta. Hän on monsieur Baptiste — mies,
jonka peli on aikamme parhainten saavutusten tasalla."

Mainittu nuori gentlemanni, jolla oli veltostuneet piirteet, kumarsi


läsnäolijoille. Alkoi vedonlyönti. Vihreä verka tuli kirjavaksi viiden
frangin rahoista, joitten joukossa pienet kultakolikot pistivät
loistavina silmään.

Yleisö ei tuntunut olevan täysin selvillä asemasta. Kukaan ei


tuntenut uutta pelaajaa. Joukossa oli niitä, jotka uskalsivat
pienempiä summia hänen puolestaan, mutta pelikassanhoitajalle tuli
vaikeaksi saada vetorahoihin tasapainoa. Hän huusi kerta toisensa
jälkeen: puuttuu sata francia monsieur Baptisten puolesta.

Viimein hän näytti aikovan pitää asian selvitettynä. Mutta viime


hetkessä astui esiin nuori, häikäisevän kaunis nainen, joka viskasi
kymmenen louisdoria kokeilevan biljardiprofessorin paikalle. Ja
muutamaa minuuttia myöhemmin peli alkoi.

Monsieur Baptisten huomio oli ilmeisesti kiintynyt johonkin, joka ei


kuulunut peliin. Hänen kalpeille, tylsille kasvoilleen oli äkkiä
ilmestynyt hämmästyneen kysyvä ilme. Oli selvää, että tuo nuori
nainen, joka niin rohkeasti oli vaarantanut rahansa hänen takiaan, ei
ollut hänelle aivan outo. Hänen huulensa liikkuivat, ikäänkuin hän
muistelisi jotakin. Mutta hän ei katsonut sinne päin, missä nainen
istui — ylpeänä ja yksinään hienossa, mutta yksinkertaisessa
sinisessä kävelypuvussaan.
Seuraavassa silmänräpäyksessä peli alkoi. Ei kuulunut muuta kuin
pienten norsunluupallojen kieriminen vihreällä veralla. Ei koskaan
ollut Curen loistava vapaatyrkkäys herättänyt niin suurta riemua eikä
koskaan Gibelinin ihanat ristipallot olleet niin hyvin lasketut. Jo
ensimäisessä kierroksessa huomasi, että pelistä tulisi kova ottelu.

Muukalainen herätti aluksi pettymystä. Hänen ensimäinen pallonsa


ei sattunut ja sitä tervehdittiin yleisön puolelta tyytymättömällä
nurinalla. Pelattiin vain punaisesta pallosta sataan. Cure oli
ensimäisellä lyönnillään tehnyt neljäkolmatta pistettä, Gibelin
kahdeksan ja Maquet viisitoista, kun sitä vastoin muukalainen ei
vielä ollut saanut yhtään. Ranskalainen mestari sai kuitenkin
asennon, jossa hän epäonnistui. Myöskin Gibelin ja Maquet
epäonnistuivat ja viimemainitun oli monsieur Baptistelle jätettävä
nurkka-asento, joka sai koko tuon erikoisen asiantuntevan yleisön
tuijottamaan jännityksestä. Yksinpä keskinkertainenkin pelaaja voisi
siitä saada pitkän sarjan lyöntejä.

Nuori herrasmies tarttui keppiinsä ja katseli ympärilleen hymyillen.


Hän mietti hetkisen. Sitten hän erotti kaksi palloa toisistaan
päättäväisellä lyönnillä. Hän ei tahtonut käyttää hyväkseen
satunnaista etuaan.

Voimakkaat suosionosoitukset suurimmalta osalta seuruetta olivat


vastauksena tälle liikkeelle, kun taas ne, jotka olivat uskaltaneet
rahojaan uuden tulokkaan puolesta, kuuluivat panevan hiljaisia
vastalauseita.

Nyt näkyi kuitenkin, että monsieur Baptiste osasi asiansa. Hän


käytteli keppiään loistavasti ja hänen pelikumppaninsa taputtivat
tuon tuostakin käsiään hänen hienolle ja hyvin harkitulle pelilleen.
Mutta Cure oli tänä iltana vauhdissaan. Hän pelasi oikein con
amore hänelle ominaisella kevyellä, tyynellä ja ylivoimaisella tavalla.
Etevä mestari saavutti jo kolmannella kierroksella kahdeksan
yhdeksättä pistettä ja olisi helposti voittanut pelin, jos ei olisi
unohtanut liiduta keppiään. Tämä aiheutti sen, että hän löi sivu
melkein valmiiksi asetetun pallon. Kolme muuta olivat kuitenkin
sangen paljon jälessä. Gibelinillä oli kahdeksankahdeksatta,
Maquet'lla neljäkuudetta ja monsieur Baptistella neljäseitsemättä
pistettä. Kaikki viittasi siis siihen, että Cure veisi tänäkin vuonna
mestaruuden.

Mutta kävi toisin kuin oli laskettu. Vasta nyt monsieur Baptiste
tuntui lämpenevän. Hän ei pyrkinyt loistamaan taituruuspalloilla,
vaan pelasi sangen harkitusti. Jo kolmannella lyönnillä hän sai kaksi
palloa nurkkiin ja alkoi sitten iskeä pelattua palloa kahta muuta
vasten. Tällä tavalla hän oli täysin varma sadasta pallosta.

Cure puri huultaan ja kohautti olkapäitään. Sille asialle ei


mahtanut mitään. Monsieur Baptiste julistettiin voittajaksi ja ne
muutamat, jotka olivat lyöneet hänestä vetoa, kiittivät onneaan.

Hänen kylmiin silmiinsä oli tullut omituinen ilme. Voitolla ei


tuntunut olevan häneen mitään suurempaa vaikutusta. Hänen
katseensa riippui tuossa nuoressa naisessa, joka nyt mitä
välinpitämättömimmin elein korjasi kultarahat vihreältä veralta.
Pelaaja ei nähnyt, että hänen valkeat kätensä vapisivat jännityksestä,
jolla ei ollut mitään tekemistä kullanhimon kanssa. Voittaja tunsi vain
hänen läheisyytensä ja himon omistaa tuo nainen, joka kerran ennen
oli ilmestynyt hänen tielleen.

Monsieur Baptiste oli hyvin kalpea. Hän kumartui naista kohti.


"Onko teillä mitään sitä vastaan, miss Westinghouse", hän sanoi
nopeasti, "että saatan teidät täältä pois?"

Nainen katsoi häntä hymyillen.

"Ei, monsieur Courbier", hän vastasi tyynesti. "Se on minusta


hyvin hauskaa."
XXXVIII.

PAILLARDIN LUONA.

Courbier astui ovenvartijan luo ja pisti hänen käteensä


kahdenkymmenen frangin rahan.

"Katsokaa, että kukaan ei tule minua häiritsemään,


ymmärrättekö", sanoi hän tuimasti.

"Kuten käskette, herra", Paillardin pyhäkön arvoisa vartija vastasi,


päästäen kultakolikon huomaamatta putoamaan loistavan
virkapukunsa taskuihin.

Courbier astui hallin kuvastimen eteen ja tarkasti tyydytyksellä


hienoa olemustaan. Sitten hän meni iloisesti vihellellen hänelle
varattuun pieneen yksityishuoneeseen. Hän käsitti, että tämä tilanne
voisi käydä hänelle vaaralliseksi. Mutta hän oli nyt kerta kaikkiaan
semmoisia seikkailijoita, jotka tahtovat pelata elämästään viimeistä
voittoa, ja Evy Westinghousen säteilevä katse oli ilmestynyt hänen
sieluunsa ja esti häntä ajattelemasta selvästi.

Courbier ei ollut tyhmä. Hän tajusi, että kaunis amerikatar ei ollut


ainoastaan sattumalta tullut hänen tiellensä sekä että hänen
esiintymisensä merkitsi viimeistä ponnistusta saada käsiinsä
kadoksissa oleva tohtori Fjeld.

Mutta hän ei pelännyt tätä yritystä. Olihan hänellä syytä luulla,


että tuo norjalainen lääkäri makasi meren pohjalla Dogger-
matalikolla. Ja ilman tohtori Fjeldiä tuo nuori nainen oli vain kuin
korsi tuulessa joutuessaan päättäväisen miehen käsiteltäväksi.

Evy Westinghouse istui juuri naistenhuoneessa antaen


kamarineidon järjestellä tukkaansa. Hän oli kalpea ja hänen
huulensa olivat lujasti yhteenpuristetut. Hänkin tiesi, että kohtaus
tuon miehen kanssa, jota hän oli ajanut viime viikon takaa, voisi tulla
hänelle kohtalokkaaksi. Mutta hän luotti onneensa, rohkeuteensa ja
siihen ihailuun, jonka hän aivan selvään luki nuoren rikollisen
harmaista silmistä. Hän oli tietoinen voimastaan ja aikoi käyttää sitä
loppuun saakka saadakseen selvän tohtori Fjeldin kohtalosta.

Sen tähden hän nyt istui Paillardilla, koko Pariisin hienoimmassa


elostelijain ravintolassa, valmiina illastamaan nuoren miehen kanssa,
jonka hän tiesi älykkääksi murhaajaksi ja tappajaksi. Hänen
kulkiessaan ohitse ovenvartija kumarsi kohteliaasti tälle loistavalle
ilmestykselle. Miehellä oli ollut monet tilaisuudet nähdä Pariisin
kauneimpien naisten kulkevan ohitseen. Tämä pikku ravintola
bulevardin ja Chaussée d'Antin'in nurkkauksessa ei ollut näet
ainoastaan herkuttelijain ilo, vaan myöskin hienon, kevyen
naismaailman mielipaikka. Mutta ei tuo lihava vartija ollut vielä
koskaan nähnyt niin ihanaa naista kuin tämä nuori neitonen, joka nyt
tyynin askelin kävi suoraan perikatoaan kohti.

Ovenvartija kohautti olkapäitään ja pisti taskuunsa


kahdenkymmenen frangin kolikkonsa, joka vapautti hänet kaikista
siveellisistä huolistaan.
Mutta varatun yksityishuoneen kynnyksellä nuori amerikatar
pysähtyi. Hän kääntyi ovenvartijaan, joka syvään kumartaen oli
tarttunut ovenripaan avatakseen hänelle oven.

"Malttakaahan hiukan, herraseni", hän sanoi. "Tahdotteko tehdä


minulle pienen palveluksen? Kello on nyt puoli yksitoista. Kun kello
on puoli kaksitoista, on teidän lähetettävä tarjoilija ilmoittamaan
minulle, että autoni on tullut. Hänen ei tarvitse koputtaa ovelle.
Ymmärrättekö?"

Kyllä, ovenvartija ymmärsi, sillä hänen käskevällä äänellä


lausumaansa toivomusta säesti setelirahan rapina. Se oli ääni, jonka
tuo kelpo mies oli kuullut monasti ennen ja jolle hän osasi antaa
arvon. Hänen kätensä puristui kirjavan paperin ympäri ja hän
vakuutti, että rouvan määräys suoritettaisiin täsmälleen.

Pienessä, hienossa rococo-huoneessa, jossa Vatteaun maalaukset


koristivat seiniä loistavissa kultakehyksissä, seurasi sitten pieni
iloinen illallinen. Ei olisi voinut uskoa, että siinä istui kaksi vihollista
väijyen toisiaan.

Courbier oli ylen hauskalla tuulella. Hän joi ahkeraan vanhaa


viiniä, jota tarjoiltiin aluksi, eikä suinkaan säästellyt sampanjaakaan,
kun sen vuoro tuli. Hänen keskustelunsa luiskahti sangen pian
rohkeille urille.

"Näin teidät, miss Westinghouse, ensimäisen kerran Kristianiassa.


Se tapahtui Grand Hotel'issa. En koskaan ole nähnyt ihanampaa
näkyä. Sillä hetkellä vannoin pyhän valan."

"Minkä valan?" neito kysyi keimailevasti.


Courbier ei vastannut heti. Sitten hän kumartui pöytätoveriaan
kohti.

"Semmoisen valan, että minun täytyy kerran saada omistaa


teidät", hän kuiskasi.

Evy VVestinghouse aikoi nousta seisomaan, mutta istui heti jälleen


paikalleen. Hänestä tuntui kuin käärme olisi pistänyt häntä.

"Te ette puhu niinkuin ranskalainen", hän virkkoi äänellä, jota hän
ei voinut estää värähtämästä.

Courbier nauroi.

"Olette mennyt ansaan, miss Evy", hän virkkoi. "Luuletteko


todellakin, että en ole arvannut aikeitanne? Olette hakenut käsiinne
minut saadaksenne tietoja tuosta ystävästänne, norjalaisesta, jolla
on niin kamala nimi. Mutta minä annan teille anteeksi. Sillä minä
rakastan teitä mielettömyyteen asti."

Courbier nousi ja tarttui häntä kädestä. Neito tempasi sen pois ja


heitti pikaisen silmäyksen kultaisessa rannerenkaassaan olevaan
pikku kelloon, joka näytti muutamia minuutteja vailla puoli
kaksitoista.

"Mainitsitte jostakin norjalaisesta", hän sanoi yrittäen naurahtaa.


"Mitä tiedätte hänestä?… Ehkäpä voisimme sopia…"

Courbier päästi hänen kätensä ja muutti tuolinsa lähemmäksi


häntä.

"Yhdestä suudelmasta voisin kääntää sieluni nurin teille", hän


sanoi.
"Ette ole katuva tätä yötä."

"Missä on tohtori Fjeld?" Evy jatkoi huulet vapisten.

"Hän on kuollut", Courbier lausui raa'asti nauraen. "Heitimme


hänet erääseen suureen reikään — reikään, jonka nimi on meri.
Menkää Dogger-matalikolle ja kysykää kampeloilta, missä hän on. Ne
voisivat kertoa teille hänen autuaasta lopustaan. Mutta mitäpä meillä
on hänen kanssaan tekemistä! Palvokaamme iloa ja elämää ja
rakkautta… Kuinka sanookaan Verlaine — —"

Courbier nousi seisomaan ja laski käsivartensa nuoren naisen


vyötäisille. Hän koetti vetää neidon syliinsä. Silloin ovi äkkiä aukeni
ja kynnykselle ilmestyi tarjoilija.

"Auto odottaa rouvaa", hän kiljasi kimakalla äänellä.


XXXIX.

PETTYNYT.

Courbier katseli raivoisin silmin auton jälkeen, joka hävisi


bulevardia alaspäin. Hän pui nyrkkiä ajatellessaan, kuinka lähellä oli
ollut päämääräänsä ja kuinka kaunis tuo amerikatar oli ollut
istuessaan häntä vastapäätä.

Hän oli viime kuukausina haaveillut vain noista syvistä, säteilevistä


silmistä ja tuosta päättäväisestä suusta, joka loi noille kauniille
kasvoille kaikkia miehiä niin ärsyttävän, kirpaisevan ilmeen.

Nyt Evy Westinghouse oli päässyt hänen käsistään juuri silloin, kun
hänen rusohuulensa olivat niin lähellä loistaneet hänen silmissään.
Mikä nauta hän olikaan! Ja yhtäkkiä hän tuli ajatelleeksi erästä asiaa,
joka sai hänet pysähtymään kävelyssään ravintolahuoneen
permannolla. Se oli eräs tieto, jonka hän keskustelun kuluessa oli
antanut paroni de Nozier'n akvariumista Antwerpenissä. Se oli
luiskahtanut hänen suustaan hänen jo uskoessaan, että tuo nuori
nainen lähtisi Paillardin ravintolasta häpeän leima huulilla, joita hän
nyt ei ollut edes suudellut. Ilmeisesti hän oli antanut pettää itsensä.
Mutta norjalaisen täytyi olla kuollut. Hän muisti sen yön, jolloin de
Nozier syöksyi suuren kalastajalaivan sisustasta katseessaan
sellainen ilme kuin olisi nähnyt helvetin kauhuja. Töin tuskin hän
kykeni sopertamaan muutamia värähteleviä sanoja siitä, että tohtori
Fjeld oli yhdessä Ribeiran kanssa salvattuna konehuoneeseen.

Sinne lähetettiin kymmenen miestä, jotka olivat aseistetut


hampaita myöten. Heidän oli pakko räjähdyttää ovi, kun Nozier oli
hukannut avaimen.

Huoneesta, jota valaisi vain yksi katossa oleva lamppu, he löysivät


Ribeiran raivosta kuohuen. Hänet oli sidottu hyvin lujasti. Entinen
lähetyssaarnaaja makasi vielä tiedotonna päähänsä saamastaan
iskusta.

Mutta norjalainen oli poissa. Eikä ollut suinkaan erikoisen vaikeata


ymmärtää, mihin hän oli joutunut. Raskaalla rautaseipäällä hän oli
hakannut reiän lasipermantoon ja liukunut siitä mereen.

Ribeira oli ollut raivoissaan siitä, että norjalainen oli päässyt pois
laivasta. Portugalilainen olisi tahtonut niin mielellään antaa
viholliselleen tuntuvan muiston siitä tavasta, jolla Coimbran mies
kostaa karsimansa solvauksen.

Mutta nyt meri oli niellyt tuon rohkean norjalaisen. Siitä ei,
Jumalan kiitos, voinut olla epäilystäkään. Kaikki viittasi siihen, että
Fjeld oli hyvin yksinkertaisesti hukkunut, mikäli laivan potkurit eivät
olleet silponeet häntä kappaleiksi.

Nozier raukka! Hän ei sen päivän perästä tullut enää koskaan


täysin entiselleen. Joku varjo näytti seuraavan häntä — miehen
varjo, jonka pitkät käsivarret lakkaamatta liikkuivat hänen ohkaista
linnunkaulaansa kohti.

Nyt hän istui akvariumissaan Antwerpenissä tehden kokeita


kaloillaan. Hänen silmiinsä oli ikäänkuin tullut noitten suurten
porsliinipallojen maidonvalkea loiste. Ja päivä päivältä hänen laihat
kätensä vapisivat yhä enemmän. Hän ei mennyt koskaan ulos.
Hänen sieluunsa oli tullut kauhu, joka kalvoi hänen järkeään…

Courbier ajatteli tätä kaikkea hitaasti astellessaan bulevardia


ylöspäin. Nuori biljardimestari ei tuntenut lainkaan iloa voitostaan.
Hänet valtasi harmaan illan tunnelma. Hän oli ollut onnen valikoimia
suosikkeja. Hän ei ollut koskaan nähnyt onnettomuuden tuijottavan
vastaansa sillä tavoin kuin tänä syysyönä Italialaisella bulevardilla.
Ihmiset kulkivat viluissaan ohuissa vaatteissa. Oli semmoinen yö,
jolloin kesän viimeiset ruusut kuolevat rautaisen yön kovassa
kouristuksessa.

Häntä vastaan tuli pieni parisilainen ilotyttö, joka hipaisi häntä


käsipuolesta aivankuin kissanpoika, joka pyrkii lämmittelemään.
Courbier tyrkkäsi hänet luotaan tyytymättömänä ja jatkoi kävelyään.
Opera-torilla hän pysähtyi. Mihin hän oli menossa? Hän tiesi, että
toverit olivat kokoontuneina pieneen peliklubiin, jossa saattoi palvoa
Pariisin kaikkia salaisia iloja aina kirkkaaseen päivään saakka.

Mutta hänen hyvä tuulensa oli kadonnut. Evy Westinghousen


ihanat silmät olivat imeytyneet hänen silmäteriinsä. Häneen oli
sattunut ase, joka osasi löytää miehen sydämen ja häikäistä hänen
mielensä.

Tämä yksi ainoa ajatus täytti koko hänen sielunsa: kuinka hän
voisi valloittaa tuon ylpeän ja ihanan naisen? Hän sommitteli mitä
omituisimpia suunnitelmia, mutta hän ei ollut koskaan ollut mikään
alotteen-mies.

Jospa vain Nozier olisi ollut täällä! Hänen aivonsa olivat


kaikenlaisten helvetillisten kujeilujen työpaja. Mutta pikku paroni istui
yhä kalojensa luona Antwerpenissä ja askarteli ainoastaan niitten
kanssa, kun taas uiva ruumisarkku lojui Sibirian telakalla, missä sen
suunnattomia aarteita tyhjennettiin.

Hänen ohitsensa ajoi verkalleen auto. Courbier mietti


silmänräpäyksen. Se oli suuri Limousin-auto Panhard & Levasseurin
tehtaasta ja sen tukeva komeus miellytti häntä. Ohjaaja oli voimakas
mies, urheilulakki painettuna syvään kasvoille.

Hän astui bulevardille avaamaan ovea Courbier'lle.

"Mihin herra haluaa ajettavan?" hän kysyi.

Courbier kohautti olkapäitään ja astui valaistuun autoon.

"Ajakaa mihin hiiteen tahansa", hän vastasi nyreissään ja


heittäytyi tyynyjen nojaan.

"Sepä hauskaa", ohjaaja vastasi tyynesti. "Olen menossa


Antwerpeniin ja minulla on taskussa passi erästä sairasta henkilöä
varten."

Courbier nousi istuimeltaan säikähtyneenä. Mutta samassa


sammutettiin valo vaunusta. Hän tunsi jotakin pehmeätä painettavan
suutansa vasten ja vaunu täyttyi väkevästä, imelästä hajusta. Jean
Baptiste ei kyennyt enää tekemään vastarintaa. Hän vaipui kalpeisiin
unelmiin Evy Westinghousen harmaista silmistä ja punaisista
huulista.
Mutta ohjaaja istui paikalleen ja ajoi tavanmukaista vauhtia S:t
Quen'in työläiskorttelia kohti. Siellä hän otti vaunuun pikku pojan,
joka seisoi aivan kaupungin portilla, ja lasketti sitten yön pimeyteen,
minkä pyörät ja kumit vain kestivät.
XL.

NOZIER'N AKVARIUMI.

Kaukana Schelde-joen suistamolla Antwerpenin satamassa on iso,


punainen talo, joka on huolellisesti pensaitten ja puitten peitossa. Se
on yhteydessä joen kanssa pitkällä maanalaisella käytävällä, joka on
kaivettu vedenpinnan alapuolelle ja voidaan sulkulaitteella laskea
veden alle.

Tämän talon omisti valtamerentutkija, paroni de Nozier, jolla oli


siinä laboratorionsa ja akvariuminsa. Kaikki ihmiset tiesivät sen.
Mutta kukaan ei voinut kehua koskaan astuneensa jalkaansakaan
tämän omituisen tiedemiehen pyhäkköön.

Jättiläismäinen valtameren uiva telakka oli laiturissa sulkulaitteen


ulkopuolella. Mutta pieni paroni eli akvariumissaan. Se oli hänen
mailmansa. Hän saattoi istua tuntikausia vaipuneena katselemaan
kalojansa, jotka myllersivät raittiissa vedessä suuressa lasisäiliössä.
Ne olivat kaikki hänen ystäviään ja kaikki ne tunsivat hänet.

Tuon tuostakin hän nousi pieniä portaita lasisäiliön aukolle


heittämään ruokaa ystävilleen, jotka leikkivät sen pohjalla ja
tuijottivat häneen ilmeettömillä silmillään. Silloin paronin katse voi
saada synkän kiillon.

Tässä oli koko hänen elämänsä ja tässä hän tunsi itsensä


onnelliseksi. Hän ymmärsi kaloja ja kalat ymmärsivät häntä. Ja
merkillisintä oli, että kaikki kalat de Nozier'n altaassa olivat ystäviä
keskenään. Useimmat niistä olivat luonnostaan toistensa vihollisia.
Särki ja hauki livahtivat toistensa ohi mitä veljellisimmässä
sovinnossa, eivätkä edes siinä olevat pienemmät haikalankaan lajit
hätyyttäneet heikompia tovereitaan. Ne elivät kaikki kuin loihditussa
paratiisissa.

Mutta aivan akvariumin pohjalla loisti kaksi pyöreätä silmää, joissa


oli himmeä opalinvärinen hohde. Ne tuijottivat vihreän veden läpi
omituisin, sokein katsein, joka tuntui hurmaavan kaikki kalat.

Paroni de Nozier suli kokonaan tähän maailmaansa, joka oli hänen


ainoansa. Sen yön jälkeen, jona tohtori Fjeldin kovat kourat ja
ivalliset sanat olivat Pohjanmerellä lannistaneet hänet, hän ei ollut
enää oma itsensä. Hän kuihtui ja tuli vaiteliaaksi ja alakuloiseksi.
Hänen hento ruumiinsa tuli yhä pienemmäksi päivä päivältä. Ei edes
Courbier voinut enää piristää häntä. Ranskalainen oli täyttänyt
tehtävänsä. Bretagnen ranskalaiset sardiinitehtaat olivat saaneet
hyvityksen. Kalat oli houkuteltu pois Norjan rannikoilta. Nyt saivat
norjalaiset turhaan yrittää. Kirotut norjalaiset tuotteet, jotka vuosi
vuodelta olivat yhä enemmän vallanneet maailmanmarkkinat, olivat
nyt Nozier'n neron avulla käyneet harvinaiseksi tavaraksi.

Eikä nyt enää ollut olemassa mitään esteitä. Tohtori Fjeld oli
kuollut ja Courbier saattoi rauhassa nauttia taloudellista voittoaan ja
pelata biljardia yksinomaan huvikseen.
Mutta elämähän on nyt kerta kaikkiaan yllätysten murheenlaakso.
Niinpä tapahtui eräänä aamuna paroni de Nozier'n istuskellessa
tapansa mukaan katselemassa kalojaan, että palvelija tuli hänelle
ilmoittamaan, että Courbier oli tullut häntä tapaamaan ja halusi
puhutella häntä.

Paronin teki mieli antaa kieltävä vastaus. Hän oli aivan kokonaan
unohtanut keskustelutaidon ihmisten kanssa eikä halunnut tulla
häirityksi.

Mutta ennenkuin hän oli kerinnyt avata suutaan, aukesi akvariumin


ovi ja huoneeseen astui pitkä mies, joka kantoi Courbier'tä. Heti
hänen takanaan näkyi vanhempi, harmaantunut herra, jolla oli
viisaat ja terävät silmät, sekä pieni, voimakas, tumma herra, jolla oli
nopeat ja vilkkaat liikkeet.

Aivan oven suussa seisoi hento poika, jolla oli harvinaisen kauniit
piirteet.

Nozier hypähti pystyyn. Oli helppo kuulla, kuinka hampaat kalisivat


hänen suussaan.

"Tohtori Fjeld", hän sopersi.

Pitkä mies laski nyt taakkansa lattialle. Hän oli hyvin kalpea ja
näytti saaneen kestää monia koettelemuksia. Hänen poskensa olivat
kuopalla, mutta hänen silmänsä loistivat ja hänen pitkä
jättiläisvartalonsa oli yhä voimakas ja suora siinä yksinkertaisessa
autonohjaajan puvussa, joka hänellä oli yllään. Hän kumartui de
Nozier'ta kohti.
"Siis tapaamme jälleen", hän lausui selvällä ja tyynellä äänellä. "Te
ette saanut minua hengiltä, paroni. Mutta myönnän, että se riippui
vain hiuskarvasta. Kolme vuorokautta uiskentelin Pohjanmerellä
lankulla, jonka löysin työhuoneestanne uivassa ruumisarkussa.
Tehtyäni tilinpäätöksen elämäni kanssa ja ollessani valmis
luopumaan lankusta, tuli eräs englantilainen hinaajalaiva, joka
korjasi minut ylös. Virkosin jälleen henkiin ja minut vietiin
Grimsbyhyn. Nyt olen valmis alkamaan uudestaan siitä, mihin
viimeksi lopetimme."

Paroni katsoi kauhistuneena toisesta toiseen. Hänen katseensa


pysähtyi
Courbier'hen.

"Onko hän kuollut?" hän kysyi.

"Ei", tohtori Fjeld vastasi. "Hän on vain saanut kloroformia. Mutta


käykäämme asiaamme. Tässä on pari herraa, jotka haluavat
puhutella teitä. Sallikaa minun esitellä: herra Christian Bjelland
Stavangerista — paroni de Nozier."

"Hauskaa tutustua", paroni sanoi hajamielisesti ja tuijotti tuota


tummaa miestä, jolla oli kultasankaiset nenälasit. "Ja kuka tämä
herra on?" hän kysyi synkästi.

"Hän on mr Angus Watson, herra paroni, norjalaisten


kalastusliikkeiden ystävä."

Pieni belgialainen kääntyi heistä pois ja vaipui unelmiinsa.

"Vihollinen", hän virkkoi itsekseen.


XLI.

PARONI DE NOZIER'N HAUTA.

Paroni katsahti äkkiä ylös ja remahti nauramaan. Se teki aivan


saman vaikutuksen kuin jos mielisairas henkilö olisi yhtäkkiä saanut
hetkeksi järkensä takaisin.

"Hyvät herrat", hän lausui katse tähdättynä akvariumiin.


"Katsokaahan tuota pientä parvea, joka on tuolla altaassa
vasemmalla. Nuo voimakkaat, hopeanhohteiset kalat, jotka
pysyttelevät hieman erossa toisista, ovat sardiineja — niitä hyviä
ranskalaisia sardiineja, jotka eivät vielä ole kulkeneet Englannin
kanavan läpi. Te ette pidä siitä kalasta, mr Watson. Mutta
odottakaahan hiukan… Näettekö tuon suuren parven, joka juuri
kääntyy nurkassa? Ne ovat meren ihmeellisimpiä olennoita. Niin,
herra Bjelland, näen, kuinka silmänne loistavat Ja syystä kylläkin,
sillä te olette antanut brislingille maailmanhistoriallisen nimen — te
ja mr Angus Watson. Minusta on asia yhdentekevää. Minähän olen
mies, jolla ei ole isänmaata — minun kotinani ovat suuret syvyydet…
Mutta brislingiä monet vihaavat. Kysykäähän Bretagnen asukkailta!
Ja kysykää Jean Baptiste Courbier'ltä, kunhan hän herää. Hän on
syntyisin niiltä seuduin. Me tapasimme toisemme ja huomasimme,
että kummallakin meillä oli yhteisiä harrastuksia. Mutta hänellä oli
muuan erikoisharrastus, joka liitti meidät entistä lujemmin yhteen.
Hänen elämänsä päämääränä oli nujertaa Norjan säilyketehtaat Ja
nythän herrat voivat huvitella itseään miettimällä, kuka oli hänen
takanaan."

Pikku paroni näytti saaneen takaisin rehevän sukkeluutensa. Kuta


vilkkaammin hän puhui, sitä pienemmäksi hän tuli istuessaan isossa
nojatuolissaan. Häijy ja vaarallinen kääpiö, silmissään meren himmeä
ja kohtalokas lohikäärmeenkatse…

Tunnetun valtamerentutkijan ulkomuodossa oli jotakin loihtivaa.


Hänen kalpeilla kasvoillaan tuntui olevan kuoleman leima. Hän ei
puhunut enää, mutta hänen katseensa oli kuin naulattuna noihin
suuriin porsliinipalloihin, jotka muodostivat kiinteän kohdan kalojen
merkillisessä kiertokulussa.

Silloin Bjelland astui hänen eteensä.

"Olette tehnyt meille paljon vahinkoa, paroni de Nozier", hän sanoi


hiljaa. "Tuhannet ovat nähneet nälkää ja vilua teidän tähtenne pitkin
koko Norjan rannikkoa. Me voisimme kyllä rangaista teitä. Mutta me
emme tahdo tehdä teille mitään pahaa… Tohtori Fjeldin avulla
olemme saaneet tietoomme teidän ihmeellisen, mutta tuhoisan
keksintönne. Mutta nyt tiedämme myöskin, kuinka meidän on
puolustauduttava… Brislinki on jälleen löytävä tavanmukaisen tiensä
Norjan vuonoihin ja turska on jälleen etsivä lempipaikkojaan suurilla
matalikoilla… Niin, emme tahdo teille mitään pahaa, paroni de
Nozier. Sillä me ymmärrämme, että te tieteen maailmassa olette
päätänne pitempi useimpia muita. Mutta Jean Baptiste Courbier, joka
niin kavalasti hiipi joukkoomme ja väärinkäytti
vieraanvaraisuuttamme ja joka…"
Herra Bjelland Stavangerista keskeytti äkkiä puheensa. Courbier oli
noussut pystyyn ja katseli vastustajiaan häijyin ja vihaisin silmin. Hän
taisteli vielä kloroformin vaikutuksia vastaan, mutta hänen nyrkkiin
puristetut kätensä ja yhteenpuristetut huulensa todistivat pedon
heränneen hänessä henkiin…

Fjeld veti esiin revolverinsa, mutta Courbier'n verestävät silmät


etsivät toista päämaalia. Hän oli nähnyt ovella eräät kasvot. Siellä
seisoi nuori poikanen. Jean Baptiste oli jo tuntenut nuo loistavat
silmät. Hän oli Evy Westinghouse — amerikatar, joka oli pettänyt
hänet ja joka nyt seisoi kumartuneena ovea vasten
ruumiinmukaisessa pojanpuvussaan ja katseli tohtori Fjeldiä ihanilla
silmillään.

Hän puri hammasta. Hoikka väkipuukko kiilsi hänen kädessään ja


yhdellä ainoalla hyppäyksellä hän oli miesten takana. Arvelematta
hän syöksyi amerikatarta kohti käsi koholla.

Mutta Evy Westinghouse oli varuillaan. Silmää räpäyttämättä hän


vastaanotti vaarallisen hyökkäyksen ja samassa kun Courbier'n
kiroten piti työntää kuolemaa tuottava aseensa hänen ruumiiseensa,
hän kumartui nopeasti ja heittäytyi permannolle.

Jos ei huumausaine enää olisi vaikuttanut Courbier'ssä, niin hän


olisi ehkä saavuttanut tarkoituksensa. Nyt tikari vain hipasi neidon
olkapäätä. Courbier kompastui hänen ruumiiseensa ja kaatui lattialle.
Mutta hän nousi salamannopeudella pystyyn ja kääntyi jälleen
uhriaan vastaan.

"Varokaa itseänne", neito huusi.


Mutta Jean Baptiste hyökkäsi pelkäämättä kohtaloansa kohti.
Tuommoinen pieni revolveri nuoren naisen kädessä — mitäpä
semmoinen leikkikalu merkitsi!

Mutta tuo pieni, kiiltävä leikkikalu ratkaisi hänen kohtalonsa.


Laukaus — lyhyt ja terävä…

Jean Baptiste pysähtyi puukko valmiina iskemään — hänen


kalpeilla kasvoillaan näkyi pahanilkinen virnistys. Tikari putosi hänen
kädestään ja pää painui rintaa vasten. Jalat eivät enää voineet pitää
häntä pystyssä…

Tuolilta, jossa paroni de Nozier istui kokoon lyyhistyneenä, kuului


katkera ivanauru.

"Nähkääs nyt, Jean Baptiste", hän änkytti… "Hän oli teille sittenkin
liian kova pala purtavaksi. Te vannoitte joko ottavanne hänet
omaksenne taikka kuolevanne. Kuolemapa siitä sitten tulikin…
Kuolema, ainoa rakastajatar, josta voimme olla varmat. — —"

Hän nousi hitaasti seisoalleen ja raskain, väsynein askelin hän


hoippui niille pienille portaille, jotka veivät akvariumin suulle.

Fjeld hyppäsi hänen perästään. Mutta se oli liian myöhäistä.

Paroni ei ollut enää arka. Hän ei enää pelännyt kuolemaa. Hänen


aikansa oli tullut. Ja tehden kädellään kevyen liikkeen, joka saattoi
merkitä jäähyväisiä, hän liukui syvään altaaseen.

Hänen ympärillään pärskähti voimakas vesiryöppy ja tuhannet


kalat lensivät säikähtyneinä joka puolelle. Mutta niitten säikähdys ei
kestänyt kauan. Paroni upposi kuin kivi tekemättä yritystäkään
nousta pinnalle. Hänen taskunsa olivat ilmeisesti täynnä jotakin
raskasta ainetta. Ilman mitään kuolinkamppailua pahantekijä ja
tiedemies siirtyi ikuiseen lepoon. Hän jäi makaamaan suuren
lasihuoneen pohjalle, kasvot käännettyinä loistavia porsliinipalloja
kohti.

Hän lepäsi siellä hienoinen hymy näivettyneillä huulillaan tuijottaen


siihen maailmaan, joka oli hänen omansa. Avoimiksi jääneisiin silmiin
oli tullut tumma kiilto. Eikä haikala kajonnut häneen. Se kierteli
pienissä kaarissa kuolleen ympärillä ja kerran se hipasi valkeita
kasvoja, ikäänkuin tahtoen hyväillä herraansa ja ystäväänsä —
meren synkkien arvoitusten nerokasta tutkijaa.

Mutta Evy Westinghouse seisoi kuin lattiaan kiinnikasvaneena ja


tuijotti Jean Baptiste Courbier'n vääristyneitä kasvoja. Hän astui
Fjeldin luokse ikäänkuin suojaa ja turvaa etsien.

"Tämä on hirveätä", hän sanoi heittäen aseen kädestään.

Fjeld kohautti olkapäitään.

"Kohtalomme on kuolema", hän lausui. "Toivokaamme, että


kuolema kerran tapaa meidät oikealta paikaltamme ja että
kohtaamme sen kunnialla."

Saapuvilla olleet miehet ja nuori neitonen kumarsivat päänsä ja


nuori nainen nojasi ystäväänsä vasten hänen silmiensä täyttyessä
kyynelillä.

"Minä en kelpaa tämmöisiin toimituksiin", hän lausui. "Eihän


minusta tule koskaan muuta kuin heikko nainen. Oi, sanokaahan,
mitä minun on tehtävä?"

Fjeld katsoi häntä silmiin.


"Palatkaa New-Yorkiin."

"Mitä minä siellä tekisin?" neito kysyi hämmästyen.

"Menette naimisiin", tohtori vastasi… "Sen miehen kanssa, joka


joka hetki odottaa teidän paluutanne."

Evy Westinghouse katsoi häntä suoraan silmiin.

"Ehkä", hän lausui ja heitti viimeisen silmäyksen akvariumiin,


missä kalat olivat jälleen alkaneet ikuisen kiertokulkunsa paroni de
Nozier'n haudan ympärillä.
*** END OF THE PROJECT GUTENBERG EBOOK SÄILYKEKUNINGAS
***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

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. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

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.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• 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

You might also like