100% found this document useful (1 vote)
5 views

Computer Programming 1st Edition E. Balagurusamy download

The document provides information about various programming books authored by E. Balagurusamy and others, including titles on computer programming, C programming, and Python. It also includes details about the author's background and contributions to the field of Information Technology and Management. Additionally, the document outlines the content structure of the 'Computer Programming' book, covering topics such as algorithms, C programming basics, and software development methods.

Uploaded by

kqirajotonas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
5 views

Computer Programming 1st Edition E. Balagurusamy download

The document provides information about various programming books authored by E. Balagurusamy and others, including titles on computer programming, C programming, and Python. It also includes details about the author's background and contributions to the field of Information Technology and Management. Additionally, the document outlines the content structure of the 'Computer Programming' book, covering topics such as algorithms, C programming basics, and software development methods.

Uploaded by

kqirajotonas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Computer Programming 1st Edition E.

Balagurusamy
pdf download

https://ebookgate.com/product/computer-programming-1st-edition-e-
balagurusamy/

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Programming in ANSI C 6th Edition E. Balagurusamy

https://ebookgate.com/product/programming-in-ansi-c-6th-edition-e-
balagurusamy/

ebookgate.com

C Programming Data Structures 4th Edition E. Balagurusamy

https://ebookgate.com/product/c-programming-data-structures-4th-
edition-e-balagurusamy/

ebookgate.com

Computer Programming for Teens 1st Edition Mary E. Farrell

https://ebookgate.com/product/computer-programming-for-teens-1st-
edition-mary-e-farrell/

ebookgate.com

Advanced Computer Programming in Python 1st Edition Karim


Pichara

https://ebookgate.com/product/advanced-computer-programming-in-
python-1st-edition-karim-pichara/

ebookgate.com
Computer Arithmetic Volume I Earl E Swartzlander

https://ebookgate.com/product/computer-arithmetic-volume-i-earl-e-
swartzlander/

ebookgate.com

Practical programming An introduction to computer science


using Python Jennifer Campbell

https://ebookgate.com/product/practical-programming-an-introduction-
to-computer-science-using-python-jennifer-campbell/

ebookgate.com

Programming with Java A Primer 3 e 3rd Edition E.


Balaguruswamy

https://ebookgate.com/product/programming-with-java-a-primer-3-e-3rd-
edition-e-balaguruswamy/

ebookgate.com

Mathematics for 3D Game Programming and Computer Graphics


Second Edition Eric Lengyel

https://ebookgate.com/product/mathematics-for-3d-game-programming-and-
computer-graphics-second-edition-eric-lengyel/

ebookgate.com

Numerical Computer Methods Part E 1st Edition Michael L.


Johnson

https://ebookgate.com/product/numerical-computer-methods-part-e-1st-
edition-michael-l-johnson/

ebookgate.com
As per
JNTU-Hyderabad
Syllabus regulation
2013

Computer Programming
First Edition
About the Author

E Balagurusamy, former Vice Chancellor, Anna University, Chennai, is currently Member, Union Public
Service Commission, New Delhi. He is a teacher, trainer, and consultant in the fields of Information
Technology and Management. He holds an ME (Hons) in Electrical Engineering and PhD in Systems
Engineering from the Indian Institute of Technology, Roorkee. His areas of interest include Object-Oriented
Software Engineering, Electronic Business, Technology Management, Business Process Re-engineering, and
Total Quality Management.
A prolific writer, he has authored a large number of research papers and several books. His best selling
books, among others, include:
• Computing Fundamentals and C Programming
• Fundamentals of Computers
• Programming in C#, 3/e
• Programming in Java, 4/e
• Object-Oriented Programming with C++, 5/e
• Programming in BASIC, 3/e
• Programming in ANSI C, 5/e
• Numerical Methods
• Reliability Engineering
A recipient of numerous honours and awards, he has been listed in the Directory of Who’s Who of
Intellectuals and in the Directory of Distinguished Leaders in Education.
As per
JNTU-Hyderabad
Syllabus regulation
2013

Computer Programming
First Edition

E Balagurusamy
Chairman
EBG Foundation
Coimbatore

McGraw Hill Education (India) Private Limited


NEW DELHI

McGraw Hill Education Offices


New Delhi New York St Louis San Francisco Auckland Bogotá Caracas
Kuala Lumpur Lisbon London Madrid Mexico City Milan Montreal
San Juan Santiago Singapore Sydney Tokyo Toronto
McGraw Hill Education (India) Private Limited
Published by McGraw Hill Education (India) Private Limited
P-24, Green Park Extension, New Delhi 110 016

Computer Programming, 1e
Copyright © 2014, by McGraw Hill Education (India) Private Limited.
No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise or stored in a database or retrieval system without the prior written permission of
the publishers. The program listing (if any) may be entered, stored and executed in a computer system, but they may not
be reproduced for publication.
This edition can be exported from India only by the publishers,
McGraw Hill Education (India) Private Limited.

ISBN (13): 978-93-5134-2939


ISBN (10): 93-5134-293X
Vice President and Managing Director: Ajay Shukla
Head—Higher Education Publishing and Marketing: Vibha Mahajan
Publishing Manager (SEM & Tech. Ed.): Shalini Jha
Editorial Researcher—Acquisitions: S. Vamsi Deepak
Manager—Production Systems: Satinder S Baveja
Assistant Manager—Editorial Services: Sohini Mukherjee
Senior Production Executive: Suhaib Ali
Assistant General Manager—Higher Education (Marketing): Vijay Sarathi
Senior Product Specialist: Tina Jajoriya
Senior Graphic Designer—Cover: Meenu Raghav
General Manager—Production: Rajender P Ghansela
Production Manager—Reji Kumar

Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed to be reliable.
However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or completeness of any information
published herein, and neither McGraw Hill Education (India) nor its authors shall be responsible for any errors, omissions,
or damages arising out of use of this information. This work is published with the understanding that McGraw Hill Education
(India) and its authors are supplying information but are not attempting to render engineering or other professional services.
If such services are required, the assistance of an appropriate professional should be sought.

Typeset at Text-o-Graphics, B-1/56, Aravali Apartment, Sector-34, Noida 201 301, and printed at

Cover Printer:
Content

Preface xv
Roadmap to the Syllabus xix

1. Introduction to Computers 1.1-1.50


1.1 Introduction 1.1
1.2 Computer Systems 1.2
1.2.1 Input Devices 1.3
1.2.2 CPU 1.5
1.2.3 Output Devices 1.6
1.2.4 Memory 1.8
1.3 Programming Languages 1.12
1.3.1 Machine Language 1.12
1.3.2 Assembly Language 1.12
1.3.3 High-Level Languages 1.13
1.3.4 Procedure-oriented Languages 1.14
1.3.5 Problem-oriented Languages 1.14
1.3.6 Natural Languages 1.14
1.4 Programming Environment 1.15
1.5 Creating and Running Programs 1.15
1.5.1 Structured Programming 1.15
1.5.2 System Development Tools 1.16
1.5.3 Developing a Program 1.18
1.5.4 Running a Program 1.21
1.6 Software Development Method 1.22
1.6.1 Analysing the Requirements 1.23
1.6.2 Feasibility Analysis 1.23
1.6.3 Creating the Design 1.24
1.6.4 Developing Code 1.24
1.6.5 Testing the Software 1.25
1.6.6 Deploying the Software 1.25
1.6.7 Maintaining the Software 1.25
vi Contents

1.7 Applying Software Development Method 1.25


1.8 Problem Solving 1.27
1.9 Algorithms 1.27
1.9.1 Characteristics of Algorithms 1.28
1.9.2 Advantages of Algorithms 1.28
1.9.3 Disadvantages of Algorithms 1.28
1.10 Flowcharts 1.30
1.10.1 Flowchart Design Rules 1.33
1.10.2 Advantages of Flowcharts 1.33
1.10.3 Disadvantages of Flowcharts 1.33
1.11 Pseudocodes 1.36
1.11.1 Pseudocode Rules 1.37
1.11.2 Advantages of Pseudocodes 1.37
1.11.3 Disadvantages of Pseudocodes 1.37
1.12 Problem Solving Examples 1.40
Just Remember 1.46
Multiple Choice Questions 1.47
Review Questions 1.48
Key Terms 1.49

2 Introduction to C 2.1-2.147
2.1 Introduction 2.1
2.2 Overview of C 2.2
2.2.1 History of C 2.2
2.2.2 Characteristics of C 2.4
2.2.3 Sample Program 1: Printing a Message 2.4
2.2.4 Sample Program 2: Adding Two Numbers 2.7
2.2.5 Sample Program 3: Interest Calculation 2.8
2.2.6 Sample Program 4: Use of Subroutines 2.10
2.2.7 Sample Program 5: Use of Math functions 2.11
2.3 Basic Structure of C Programs 2.13
2.4 Programming Style 2.13
2.5 Executing A ‘C’ Program 2.14
2.6 UNIX System 2.15
2.7 C Character Set 2.17
2.7.1 Trigraph Characters 2.19
2.8 C Tokens 2.19
2.9 Keywords and Identifiers 2.20
2.10 Constants 2.21
2.10.1 Integer Constants 2.21
2.10.2 Real Constants 2.22
2.10.3 Single Character Constants 2.23
2.10.4 String Constants 2.24
2.11 Variables 2.24
2.12 Data Types 2.25
Contents vii

2.12.1 Integer Types 2.26


2.12.2 Floating Point Types 2.27
2.12.3 Void Types 2.27
2.12.4 Character Types 2.27
2.13 Declaration of Variables 2.27
2.13.1 Primary Type Declaration 2.28
2.13.2 User-defined Type Declaration 2.29
2.14 Declaration of Storage Class 2.30
2.15 Assigning Values to Variables 2.31
2.15.1 Assignment Statement 2.32
2.15.2 Reading Data from Keyboard 2.34
2.15.3 Declaring a Variable as a Constant 2.36
2.15.4 Declaring a Variable as Volatile 2.36
2.16 Case Studies 2.37
2.16.1 Calculation of Average of Numbers 2.37
2.16.2 Temperature Conversion Problem 2.38
2.17 Managing Input and Output Operations 2.39
2.17.1 Reading a Character 2.39
2.17.2 Writing a Character 2.42
2.17.3 Formatted Input 2.43
2.17.4 Points to Remember while Using scanf 2.50
2.17.5 Formatted Output 2.50
2.18 Case Studies 2.55
2.19 Operators and expressions 2.59
2.19.1 Arithmetic Operators 2.59
2.19.2 Relational Operators 2.61
2.19.3 Logical Operators 2.62
2.19.4 Assignment Operators 2.63
2.19.5 Increment and Decrement Operators 2.65
2.19.6 Conditional Operator 2.66
2.19.7 Bitwise Operators 2.67
2.19.8 Special Operators 2.67
2.19.9 Operator Precedence 2.69
2.19.10 Precedence of Arithmetic Operators 2.70
2.19.11 Some Computational Problems 2.72
2.19.12 Type Conversions in Expressions 2.73
2.19.13 Operator Precedence and Associativity 2.75
2.20 Case Studies 2.78
2.21 Decision making and branching 2.79
2.21.1 Decision Making with if Statement 2.80
2.21.2 The switch Statement 2.90
2.21.3 The goto Statement 2.92
2.22 Case Studies 2.94
2.23 Decision making and looping 2.98
2.23.1 The while Statement 2.99
2.23.2 The do Statement 2.100
viii Contents

2.23.3 The for Statement 2.102


2.23.4 Jumps in Loops 2.107
2.24 Jumping out of the Program 2.112
2.25 Structured Programming 2.112
2.26 Case Studies 2.113
Just Remember 2.142
Review Questions 2.144
Multiple Choice Questions 2.145
Programming Exercise 2.146

3A. Functions 3A.1-3A.45


3A.1 Introduction 3A.1
3A.2 Need for User-defined Functions 3A.1
3A.3 A Multi-function Program 3A.2
3A.4 Elements of user-defined Functions 3A.4
3A.5 Definition of Functions 3A.4
3A.5.1 Function Header 3A.5
3A.5.2 Name and Type 3A.5
3A.5.3 Formal Parameter List 3A.5
3A.5.4 Function Body 3A.6
3A.6 Return Values and their Types 3A.7
3A.7 Function Calls 3A.8
3A.8 Function Declaration 3A.9
3A.9 Category of Functions 3A.11
3A.10 No Arguments and no Return Values 3A.11
3A.11 Arguments but no Return Values 3A.13
3A.12 Arguments with Return Values 3A.15
3A.13 No Arguments but Returns a Value 3A.18
3A.14 Functions that Return Multiple Values 3A.19
3A.15 Nesting of Functions 3A.20
3A.16 Recursion 3A.21
3A.17 The Scope, Visibility and Lifetime of Variables 3A.22
3A.17.1 Automatic Variables 3A.23
3A.17.2 External Variables 3A.24
3A.17.3 Static Variables 3A.328
3A.17.4 Register Variables 3A.29
3A.17.5 Nested Blocks 3A.30
3A.18 Multifile Programs 3A.31
3A.19 Preprocessor Commands 3A.32
3A.19.1 Macro Substitution Directives 3A.33
3A.19.2 File Inclusion Directive 3A.35
3A.19.3 Conditional Inclusion Directives 3A.35
3A.19.4 Additional Preprocessor Directives 3A.36
Just Remember 3A.37
Multiple Choice Questions 3A.38
Contents ix

Case Study 3A.39


Review Questions 3A.41
Programming Exercises 3A.44
Key Terms 3A.45

3B. Arrays 3B.1-3B.79


3B.1 Introduction 3B.1
3B.2 One-Dimensional Arrays 3B.2
3B.3 Declaration of one-dimensional Arrays 3B.3
3B.4 Initialization of one-dimensional Arrays 3B.5
3B.4.1 Compile Time Initialization 3B.6
3B.4.2 Run Time Initialization 3B.6
3B.5 Two-Dimensional Arrays 3B.14
3B.6 Initializing Two-Dimensional Arrays 3B.18
3B.7 Multi-Dimensional Arrays 3B.21
3B.8 Dynamic Arrays 3B.22
3B.9 Passing Arrays to Functions 3A.22
3B.9.1 One-Dimensional Arrays 3A.22
3B.9.2 Two-Dimensional Arrays 3A.26
3B.10 Passing Strings to Functions 3A.27
3B.11 More About Arrays 3B.27
3B.12 C Programming Examples – Built-in Functions 3B.58
Just Remember 3B.63
Multiple Choice Questions 3B.63
Case Study 3B.64
Review Questions 3B.75
Programming Exercises 3B.77
Key Terms 3B.79

4A. Pointers 4A.1-4A.35


4A.1 Introduction 4A.1
4A.2 Understanding Pointers 4A.1
4A.3 Accessing the Address of a Variable 4A.3
4A.4 Declaring Pointer Variables 4A.4
4A.5 Initialization of Pointer Variables 4A.5
4A.6 Accessing a Variable Through its Pointer 4A.6
4A.7 Chain of Pointers 4A.8
4A.8 Pointer Expressions 4A.9
4A.9 Pointer Increments and Scale Factor 4A.10
4A.10 Pointers and Arrays 4A.11
4A.11 Pointers and Character Strings 4A.14
4A.12 Array of Pointers 4A.16
4A.13 Pointers as Function Arguments 4A.16
4A.14 Functions Returning Pointers 4A.19
x Contents

4A.15 Pointers to Functions 4A.19


4A.16 Introduction 4A.22
4A.17 Dynamic Memory Allocation 4A.23
4A.18 Allocating a Block of Memory: Malloc 4A.23
4A.19 Allocating Multiple Blocks of Memory: Calloc 4A.25
4A.20 Releasing the Used Space: Free 4A.26
Just Remember 4A.26
Multiple Choice Questions 4A.27
Case Study 4A.28
Review Questions 4A.33
Programming Exercises 4A.34
Key Terms 4A.35

4B. Strings 4B.1-4B.30


4B.1 Introduction 4B.1
4B.2 Declaring and Initializing String Variables 4B.2
4B.3 Reading Strings From Terminal 4B.3
4B.3.1 Using scanf Function 4B.3
4B.3.2 Reading a Line of Text 4B.5
4B.3.3 Using getchar and gets Functions 4B.5
4B.4 Writing Strings to Screen 4B.7
4B.4.1 Using printf Function 4B.7
4B.4.2 Using putchar and puts Functions 4B.10
4B.5 Arithmetic Operations on Characters 4B.11
4B.6 Putting Strings Together 4B.12
4B.7 Comparison of Two Strings 4B.14
4B.8 String-Handling Functions 4B.14
4B.8.1 strcat() Function 4B.14
4B.8.2 strcmp() Function 4B.15
4B.8.3 strcpy() Function 4B.15
4B.8.4 strlen() Function 4B.16
4B.8.5 strncpy() Function 4B.17
4B.8.6 strncmp() Function 4B.17
4B.8.7 strncat() Function 4B.18
4B.8.8 strstr() Function 4B.18
4B.9 Table of Strings 4B. 19
4B.10 Other Features of Strings 4B. 20
4B.11 String / Data Conversion 4B. 20
Just Remember 4B. 22
Multiple Choice Questions 4B. 22
Case Study 4B. 23
Review Questions 4B. 27
Programming Exercises 4B. 29
Key Terms 4B.30
Contents xi

5. Structures and Unions 5.1-5.59


5.1 Introduction 5.1
5.2 Defining a Structure 5.1
5.3 Declaring Structure Variables 5.2
5.4 Accessing Structure Members 5.4
5.5 Structure Initialization 5.5
5.6 Copying and Comparing Structure Variables 5.7
5.7 Operations On Individual Members 5.8
5.8 Arrays of Structures 5.9
5.9 Arrays Within Structures 5.11
5.10 Structures Within Structures 5.12
5.11 Pointers and Structures 5.14
5.12 Structures and Functions 5.17
5.13 Unions 5.20
5.14 Size of Structures 5.21
5.15 Bit Fields 5.22
5.16 Typedef 5.24
5.17 Enum 5.24
5.18 Command Line Arguments 5.38
5.19 Application of Command Line Arguments 5.48
Just Remember 5.50
Multiple Choice Questions 5.51
Case Study 5.52
Review Questions 5.55
Programming Exercises 5.58
Key Terms 5.59

6. File Management in C 6.1-6.19


6.1 Introduction 6.1
6.2 Types of Files 6.2
6.3 Defining and Opening a File 6.3
6.4 Closing a File 6.4
6.5 Input/Output Operations on Files 6.4
6.5.1 The getc and putc Functions 6.5
6.5.2 The getw and putw Functions 6.6
6.5.3 The fprintf and fscanf Functions 6.8
6.6 Error Handling During I/O Operations 6.10
6.7 Random Access to Files 6.12
Just Remember 6.16
Multiple Choice Questions 6.17
Review Questions 6.18
Programming Exercises 6.19
Key Terms 6.19
xii Contents

7. Sorting and Searching Techniques 7.1-7.23


7.1 Introduction 7.1
7.2 Sorting 7.1
7.2.1 Sorting Efficiency 7.2
7.2.2 Exchange Sorting—Bubble Sort 7.3
7.2.3 Exchange Sorting—Quick Sort 7.5
7.2.4 Selection Sort 7.8
7.2.5 Merge Sort 7.10
7.2.6 Simple Insertion Sort 7.12
7.2.7 Shell Sort 7.13
7.3 Searching 7.15
7.3.1 Linear Search 7.15
7.3.2 Binary Search 7.16
7.3.3 Indexed Sequential Search 7.19
Just Remember 7.22
Multiple Choice Questions 7.22
Review Questions 7.23

8. Data Structures 8.1-8.52


8.1 Introduction 8.1
8.2 Abstract Data Types 8.2
8.3 Linear List 8.2
8.3.1 Linked Lists Operations 8.5
8.3.2 Implementation 8.10
8.3.3 Linked List with Header 8.16
8.4 Stacks 8.17
8.4.1 Stack Operations 8.18
8.5 Stack Implementation 8.18
8.5.1 Array Implementation of Stacks 8.19
8.5.2 Linked Implementation of Stacks 8.23
8.6 Applications of Stacks 8.27
8.6.1 Infix Notation 8.27
8.6.2 Prefix Notation 8.27
8.6.3 Conversion from Infix to Prefix Notation 8.28
8.6.4 Evaluation of Prefix Expression 8.31
8.6.5 Postfix Notation 8.32
8.6.6 Conversion from Infix to Postfix Notation 8.32
8.6.7 Evaluation of Postfix Expression 8.36
8.7 Queues 8.36
8.7.1 Queue Operations 8.37
8.8 Queue Implementation 8.38
8.8.1 Array Implementation of Queues 8.38
8.8.2 Linked Implementation of Queues 8.44
Contents xiii

Just Remember 8.49


Multiple Choice Questions 8.49
Review Questions 8.50
Programming Exercises 8.52

Appendix A A.1-A.12

Solved Question Papers


June 2011 Set 1 1.1–1.6
June 2011 Set 2 2.1–2.8
June 2011 Set 3 3.1–3.7
June 2011 Set 4 4.1–4.11

June 2012 SQP SET 1.1–1.8


Preface

The developments in digital electronics and related technologies during the last few decades have ushered
in the second Industrial Revolution that is popularly referred to as the Information Revolution. Computer
technology plays an ever-increasing role in this new revolution. Today, the application of computers is all
pervasive in everybody’s life. A sound knowledge of how computers process data and information has,
therefore, become indispensable for anyone who seeks employment not only in the area of IT but also in any
other field.

COMPUTER PROGRAMMING
Computer programming is dedicated to writing, testing and maintaining programs that computers follow to
perform their functions. To create programs that control the behaviour of a machine, we need programming
languages. This book enables students to master the necessary skills for computer programming with C
language and shows them how to use these skills wisely with data structures and algorithms.

THE C PROGRAMMING LANGUAGE


C is a general-purpose structured programming language that is powerful, efficient and compact. C combines
the features of a high-level language with the elements of the assembler and is thus close to both man and
machine. The growth of C during the last few years has been phenomenal. It has emerged as the language
of choice for most applications due to its speed, portability and compactness of code. It has now been
implemented on virtually every sort of computer, from micro to mainframe.
Rightly so, many institutions and universities in India have introduced a subject covering Computer
Programming. This book is specially designed for the first-year students studying the foundation course
in the first semester of Jawaharlal Nehru Technological University (JNTU).

DATA STRUCTURES
Data structures are prevalent in almost every program, since they provide specialised formats of storing and
organising data in a computer. This book presents the design and implementation of data structures using
standard ANSI C programming language.
xvi Preface

WHY IS THIS BOOK A WINNER?


• This book is completely in sync with the new syllabus prescribed by JNTU, effective August 2009.
– It offers comprehensive coverage of topics related to Data Structures, Linked Lists, Queues,
Stacks (important as per the new syllabus).
– New chapters on Fundamentals of Computers and Computing Concepts cover two new units in
the revised syllabus. These chapters clearly explain the basics of computers, thereby providing
a strong foundation for mastering advanced topics on programming and data structures given in
successive chapters.
• This book incorporates all the features of ANSI C that are essential for a C programmer. The ANSI
standards are explained in detail at appropriate places (noted in the text by a special mention for the
convenience of our readers).
• From a learner to a skilled C programmer, this book ensures smooth and successful transition. The
concept of ‘learning by example’ has been stressed throughout the book. Every important feature
of the language is treated in depth followed by a complete program example to illustrate its use.
Case studies at the end of chapters not only describe the common ways in which C features are put
together but also show real-life applications. Wherever necessary, pictorial descriptions of concepts
are included to facilitate better understanding. Thus, this book succeeds at presenting a contemporary
approach to programming with a unique combination of theory and practice.
• It highly appeals to the students because of focused coverage of syllabus, variety of programs and
simple theory.

PEDAGOGICAL FEATURES
• Bottom-up approach of explaining concepts.
• Algorithms and flowcharts are covered extensively.
• Codes and comments illustrate the use of various features of the language.
• Special boxes feature supplementary information and notes that complement the text.
• Case studies in relevant chapters demonstrate real-life applications.
• Just remember section lists out helpful hints and possible problem areas.
• Review questions (132) provide ample opportunities to test the conceptual understanding.
• Programming exercises (135) simulate interest to practice programming applications.
• Solved examples and programs (200) have been tested using compilers compatible to both UNIX
and MS-DOS operating systems and, wherever appropriate, the nature of output has been discussed.
These programs also demonstrate the general principles of a good programming style.
• Multiple choice questions (179) help students test their conceptual understanding of the subject.
• Lab assignments are given as per the new syllabus.
• Updated with information on compiler C-99 supported by numerous programs (12) using C-99.
• Solutions to 2011 exam question papers (4 sets) and 2012 exam question paper.
Preface xvii

HOW IS THE BOOK ORGANISED


The content is spread over 10 chapters. Chapter 1 introduces computer systems, programming languages
and environment, software development method, algorithms, flowcharts and pseudocodes. Chapter 2 gives
an overview of C and explains keywords, identifiers, constants, variables, data types and various case studies
on these. Chapters 3A and 3B discuss arrays and functions respectively, whereas pointers and strings are
covered in Chapters 4A and 4B. Chapter 5 presents structures and unions. Chapter 6 deals with file
management in C. Sorting and searching techniques are covered in Chapter 7. Finally, Chapter 8 presents
data structures.
There is also an Appendix and Solved Question Papers of June 2011 and June 2012 at the end of the book.

CD RESOURCES
The book is accompanied with a CD which provides the following resources:
• All lab assignments
• Previous years’ solved university question papers
• 208 additional objective/ review/ debugging type questions pertaining to each unit
• 5 Model Question Papers
The supplementary CD helps students master the programming language and write their own programs
using Computer programming concepts and data structures.

ACKNOWLEDGEMENTS
The author is grateful to Mrs Nagaratna Parameshwar Hegde of Vasavi College of Engineering, Hyderabad
for her useful comments and suggestions.

E Balagurusamy

PUBLISHER’S NOTE
McGraw Hill Education (India) looks forward to receiving from teachers and students their valuable views,
comments and suggestions for improvements, all of which may be sent to tmh.corefeedback@gmail.com
(mentioning the title and author’s name). Also, please inform any observations on piracy related issues.
Roadmap to the Syllabus
COMPUTER PROGRAMMING
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

Module 1: Introduction to Computers—Computer Systems, Computing Environments, Computer


Languages, Creating and running programs, Program Development.
Introduction to the C Language—Background, C Programs, Identifiers, Types, Variables, Constants,
Input 1 Output, Operators (Arithmetic, relational, logical, bitwise etc.), Expressions, Precedence and
Associativity, Expression Evaluation, Type conversions, Statements—Selection Statements (making
decisions)—if and switch statements, Repetition statements ( loops)-while, for, do-while statements, Loop
examples, other statements related to looping break, continue, goto, Simple C Program examples.

GO TO:
CHAPTER 1. Introduction to Computers
CHAPTER 2. Introduction to C

Module 2: Functions-Designing Structured Programs, Functions, user defined functions, inter function
communication, Standard functions, Scope, Storage classes-auto, register, static, extern, scope rules, type
qualifiers, recursion–recursive functions, Limitations of recursion, example C programs, Preprocessor
commands.
Arrays—Concepts, using arrays in C, inter function communication, array applications, two-dimensional
arrays, multidimensional arrays, C program examples.

GO TO:
CHAPTER 3A. Functions
CHAPTER 3B. Arrays

Module 3: Pointers—Introduction (Basic Concepts), Pointers for inter function communication, pointers
to pointers, compatibility, Pointer Applications-Arrays and Pointers, Pointer Arithmetic and arrays,
Passing an array to a function, memory allocation functions, array of pointers, programming applications,
pointers to void, pointers to functions.
Strings—Concepts, C Strings, String Input I Output functions, arrays of strings, string manipulation
functions, string I data conversion, C program examples.

GO TO:
CHAPTER 4A. Pointers
CHAPTER 4B. Strings
xx Roadmap to the Syllabus

Module 4: Enumerated, Structure, and Union Types—The Type Definition (typedef), Enumerated types,
Structures—Declaration, initialization, accessing structures, operations on structures, Complex structures,
structures and functions, Passing structures through pointers, self referential structures, unions, bit fields,
C programming examples, command-line arguments,
Input and Output—Concept of a file, streams, text files and binary files, Differences between text and
binary files, State of a file, Opening and Closing files, file input 1 output functions (standard library
input 1 output functions for files), file status functions (error handling), Positioning functions, C program
examples.

GO TO:
CHAPTER 5. Structures and Unions
CHAPTER 6. File Management in C

Module 5: Searching and Sorting—Sorting-selection sort, bubble sort, Searching-linear and binary
search methods.
Lists- Linear list—singly linked list implementation, insertion, deletion and searching operations on
linear list, StacksPush and Pop Operations, Queues—Enqueue and Dequeue operations.

GO TO:
CHAPTER 7. Sorting and Searching Techniques
CHAPTER 8. Data Structures
UNIT

1 Introduction to
Computers

1.1 INTRODUCTION
The term computer is derived from the word INPUT OUTPUT
compute. A computer is an electronic device Data PROCESS Information
that takes data and instructions as an input from
the user, processes data, and provides useful
information known as output. This cycle of Instructions
operation of a computer is known as the input–
Fig. 1.1 Input–process–output concept
process–output cycle and is shown in Fig. 1.1
The electronic device is known as hardware and
the set of instructions is known as software.
A computer consists of various components that function as an integrated system to perform computational
tasks. These components include the following:
• Central Processing Unit (CPU) It is the brain of the computer that is responsible for controlling
and executing program instructions.
• Monitor It is a display screen, which shows information in visual form.
• Keyboard and Mouse These are the peripheral devices used by the computer for receiving inputs
from the user.
Figure 1.2 shows the various components of a computer.
The unique capabilities and characteristics of a computer have made it very popular among its various
users, including engineers, managers, accountants, teachers, students, etc.
Some of the key characteristics of a modern digital computer include, among others the following:
• Speed The computer is a fast electronic device that can solve large and complex problems in few
seconds. The speed of a computer generally depends upon its hardware configuration.
• Storage capacity A computer can store huge amounts of data in many different formats. The storage
area of a computer system is generally divided into two categories, main memory and secondary
storage.
1.2 Computer Programming

Monitor
CPU

Keyboard

Mouse

Fig. 1.2 The components of a computer


• Accuracy A computer carries out calculations with great accuracy. The accuracy achieved by a
computer depends upon its hardware configuration and the specified instructions.
• Reliability A computer produces results with no error. Most of the computer-generated errors are
in actuality human errors that are instigated by the user itself. Therefore, computers are regarded as
quite trustworthy machines.
• Versatility Computers are versatile machines. They can perform varied tasks and can be used for
many different purposes.
• Diligence Computers can perform repetitive calculations any number of times with the same level
of accuracy.
These capabilities of computers have enabled us to use them for a variety of tasks. Application areas may
broadly be classified into the following major categories.
1. Data processing (commercial use)
2. Numerical computing (scientific use)
3. Text (word) processing (office and educational use)
4. Message communication (e-mail)
5. Image processing (animation and industrial use)
6. Voice recognition (multimedia)

1.2 COMPUTER SYSTEMS


A computer system comprises of hardware and software components. Hardware refers to the physical
parts of the computer system and software is the set of instructions or programs that are necessary for the
functioning of a computer to perform certain tasks. Hardware includes the following components:
• Input devices They are used for accepting the data on which the operations are to be performed.
The examples of input devices are keyboard, mouse and track ball.
• Processor Also known as CPU, it is used to perform the calculations and information processing on
the data that is entered through the input device.
• Output devices They are used for providing the output of a program that is obtained after performing
the operations specified in a program. The examples of output devices are monitor and printer.
• Memory It is used for storing the input data as well as the output of a program that is obtained
after performing the operations specified in a program. Memory can be primary memory as well
Introduction to Computers 1.3

as secondary memory. Primary memory includes Random Access Memory (RAM) and secondary
memory includes hard disks and floppy disks.
Software supports the functioning of a computer system internally and cannot be seen. It is stored on
secondary memory and can be an application software as well as system software. The application software
is used to perform a specific task according to requirements and the system software is mandatory for running
application software. The examples of application software include Excel and MS Word and the examples of
system software include operating system and networking system.
All the hardware components interact with each other as well as with the software. Similarly, the different
types of software interact with each other and with the hardware components. The interaction between various
hardware components is illustrated in Fig. 1.3.
1.2.1 Input Devices
Input devices can be connected to the computer system using cables. The most commonly used input devices
among others are:
• Keyboard
• Mouse
• Scanner

Magnetic Magnetic
Tape Disk

EXTERNAL STORAGE UNITS

Input Input Memory Output Output


Media Unit Unit Unit Media

Arithmetic
Unit

Control
Unit

CPU
Data and results flow
Control Instructions to units
Instructions to control unit

Fig. 1.3 Interaction among hardware components

Keyboard
A standard keyboard includes alphanumeric keys, function keys, modifier keys, cursor movement keys,
spacebar, escape key, numeric keypad, and some special keys, such as Page Up, Page Down, Home, Insert,
Delete and End. The alphanumeric keys include the number keys and the alphabet keys. The function keys
are the keys that help perform a specific task such as searching a file or refreshing a Web page. The modifier
1.4 Computer Programming

keys such as Shift and Control keys modify the casing style of a character or symbol. The cursor movement
keys include up, down, left and right keys and are used to modify the direction of the cursor on the screen.
The spacebar key shifts the cursor to the right by one position. The numeric keypad uses separate keypads for
numbers and mathematical operators. A keyboard is show in Fig. 1.4.
Function Keys
(F1 to F12)
Escape Key
Special Keys

Numeric Keypad

Modifier Keys

Alphanumeric Spacebar Key Cursor Movement


Keys Keys

Fig. 1.4 Keyboard

Mouse
The mouse allows the user to select elements on the screen, such Wheel
as tools, icons, and buttons, by pointing and clicking them. We can Right Button
also use a mouse to draw and paint on the screen of the computer Left Button
system. The mouse is also known as a pointing device because it
helps change the position of the pointer or cursor on the screen.
The mouse consists of two buttons, a wheel at the top and a
ball at the bottom of the mouse. When the ball moves, the cursor
on the screen moves in the direction in which the ball rotates. The Fig. 1.5 Mouse
left button of the mouse is used to select an element and the right
button, when clicked, displays the special options such as open and explore and shortcut menus. The wheel
is used to scroll down in a document or a Web page. A mouse is shown in Fig. 1.5.

Scanner
A scanner is an input device that converts documents and images as the
digitized images understandable by the computer system. The digitized
images can be produced as black and white images, gray images, or
colored images. In case of colored images, an image is considered as a
collection of dots with each dot representing a combination of red, green,
and blue colors, varying in proportions. The proportions of red, green, and
blue colors assigned to a dot are together called as color description. The
scanner uses the color description of the dots to produce a digitized image.
Fig. 1.6 shows a scanner.
There are the following types of scanners that can be used to produce Fig. 1.6 Scanner
digitized images:
• Flatbed scanner It contains a scanner head that moves across a page from top to bottom to read the
page and converts the image or text available on the page in digital form. The flatbed scanner is used
to scan graphics, oversized documents, and pages from books.
Introduction to Computers 1.5

• Drum scanner In this type of scanner, a fixed scanner head is used and the image to be scanned is
moved across the head. The drum scanners are used for scanning prepress materials.
• Slide scanner It is a scanner that can scan photographic slides directly to produce files understandable
by the computer.
• Handheld scanner It is a scanner that is moved by the end user across the page to be scanned. This
type of scanner is inexpensive and small in size.

1.2.2 CPU
The CPU consists of Control Unit (CU) and ALU. CU stores the instruction set, which specifies the operations
to be performed by the computer. CU transfers the data and the instructions to the ALU for an arithmetic
operation. ALU performs arithmetical or logical operations on the data received. The CPU registers store the
data to be processed by the CPU and the processed data also. Apart from CU and ALU, CPU seeks help from
the following hardware devices to process the data:

Motherboard
It refers to a device used for connecting the CPU with the input and output devices. The components on the
motherboard are connected to all parts of a computer and are kept insulated from each other. Some of the
components of a motherboard are:
• Buses Electrical pathways that transfer data and instructions among different parts of the computer.
For example, the data bus is an electrical pathway that transfers data among the microprocessor,
memory and input/output devices connected to the computer. The address bus is connected among
the microprocessor, RAM and Read Only Memory (ROM), to transfer addresses of RAM and ROM
locations that is to be accessed by the microprocessor.
• System clock It is a clock used for synchronizing the activities performed by the computer. The
electrical signals that are passed inside a computer are timed, based on the tick of the clock. As a
result, the faster the system clock, the faster is the processing speed of the computer.
• Microprocessor CPU component that performs the processing and controls the activities performed
by the different parts of the computer. The microprocessor is plugged to the CPU socket placed on the
motherboard.
• ROM Chip that contains the permanent memory of the computer that stores information, which
cannot be modified by the end user.

Random Access Memory (RAM)


It refers to primary memory of a computer that stores information and programs, until the computer is used.
RAM is available as a chip that can be connected to the RAM slots in the motherboard.

Video Card/Sound card


The video card is an interface between the monitor and the CPU. Video cards also include their own RAM
and microprocessors that are used for speeding up the processing and display of a graphic. These video cards
are placed on the expansion slots, as these slots allow us to connect the high-speed graphic display cards to
the motherboard. A sound card is a circuit board placed on the motherboard and is used to enhance the sound
capabilities of a computer. The sound cards are plugged to the Peripheral Component Interconnect (PCI)
slots. The PCI slots also enable the connection of networks interface card, modem cards and video cards, to
the motherboard.
1.6 Computer Programming

Fig. 1.7 A motherboard

1.2.3 Output Devices


The data, processed by the CPU, is made available to the end user by the output devices. The most commonly
used output devices are:
• Monitor
• Printer
• Speaker
• Plotter

Monitor
A monitor is the most commonly used output device that produces visual
displays generated by the computer. The monitor, also known as a screen, is
connected as an external device using cables or connected either as a part of the
CPU case. The monitor connected using cables, is connected to the video card
placed on the expansion slot of the motherboard. The display device is used for
visual presentation of textual and graphical information.
The monitors can be classified as cathode ray tube (CRT) monitors or liquid
crystal display (LCD) monitors. The CRT monitors are large, occupy more space
in the computer, whereas LCD monitors are thin, light weighted, and occupy Fig. 1.8 Monitor
lesser space. Both the monitors are available as monochrome, gray scale and
color models. However, the quality of the visual display produced by the CRT is
better than that produced by the LCD.
A monitor can be characterized by its monitor size and resolution. The monitor size is the length of
the screen that is measured diagonally. The resolution of the screen is expressed as the number of picture
Introduction to Computers 1.7

elements or pixels of the screen. The resolution of the monitor is also called the dot pitch. The monitor with
a higher resolution produces a clearer image.

Printer
The printer is an output device that is used to produce a hard copy of the
electronic text displayed on the screen, in the form of paper sheets that can be
used by the end user. The printer is an external device that is connected to the
computer system using cables. The computer needs to convert the document
that is to be printed to data that is understandable by the printer. The printer
driver software or the print driver software is used to convert a document to
a form understandable by the computer. When the computer components are
upgraded, the upgraded printer driver software needs to be installed on the
computer.
Fig. 1.9 Printer
The performance of a printer is measured in terms of dots per inch (DPI)
and pages per minute (PPM) produced by the printer. The greater the DPI
parameter of a printer, the better is the quality of the output generated by it. The higher PPM represents
higher efficiency of the printer. Printers can be classified based on the technology they use to print the text
and images:
• Dot matrix printers Dot matrix printers are impact printers that use perforated sheet to print the
text. The process to print a text involves striking a pin against a ribbon to produce its impression on
the paper.
• Inkjet printers Inkjet printers are slower than dot matrix printers and are used to generate high
quality photographic prints. Inkjet printers are not impact printers. The ink cartridges are attached to
the printer head that moves horizontally, from left to right.
• Laser printers The laser printer may or may not be connected to a computer, to generate an output.
These printers consist of a microprocessor, ROM and RAM, which can be used to store the textual
information. The printer uses a cylindrical drum, a toner and the laser beam.

Speaker
The speaker is an electromechanical transducer that converts an electrical
signal into sound. They are attached to a computer as output devices, to
provide audio output, such as warning sounds and Internet audios. We can
have built-in speakers or attached speakers in a computer to warn end users
with error audio messages and alerts. The audio drivers need to be installed in
the computer to produce the audio output. The sound card being used in the
computer system decides the quality of audio that we listen using music CDs
or over the Internet. The computer speakers vary widely in terms of quality
and price. The sophisticated computer speakers may have a subwoofer unit, to
enhance bass output. Fig. 1.10 Speakers

Plotter
The plotter is another commonly used output device that is connected to a computer to print large documents,
such as engineering or constructional drawings. Plotters use multiple ink pens or inkjets with color cartridges
1.8 Computer Programming

for printing. A computer transmits binary signals to all the print heads of the plotter. Each binary signal
contains the coordinates of where a print head needs to be positioned for printing. Plotters are classified on
the basis of their performance, as follows:
• Drum plotter They are used to draw perfect circles and other graphic images. They use a drawing
arm to draw the image. The drum plotter moves the paper back and forth through a roller and the
drawing arm moves across the paper.
• Flat-bed plotter A flat bed plotter has a flat drawing surface and the two drawing arms that move
across the paper sheet, drawing an image. The plotter has a low speed of printing and is large in
size.
• Inkjet plotter Spray nozzles are used to generate images by spraying droplets of ink onto the paper.
However, the spray nozzles can get clogged and require regular cleaning, thus resulting in a high
maintenance cost.
• Electrostatic plotter As compared to other plotters, an electrostatic plotter produces quality print
with highest speed. It uses charged electric wires and special dielectric paper for drawing.

Control
Buttons

Plotted
Paper

Fig. 1.11 An ink-jet plotter.

1.2.4 Memory
The memory unit of a computer is used to store data, instructions for processing data, intermediate results
of processing and the final processed information. The memory units of a computer are classified as primary
memory and secondary memory. Figure 1.12 shows the memory categorization in a computer system.
Introduction to Computers 1.9

Fig. 1.12 Categorization of Memory Devices

Primary Memory
The primary memory is available in the computer as a built-in unit of the computer. The primary memory is
represented as a set of locations with each location occupying 8 bits. Each bit in the memory is identified by
a unique address. The data is stored in the machine-understandable binary form in these memory locations.
The commonly used primary memories are:
• ROM ROM represents Read Only Memory that stores data and instructions, even when the
computer is turned off. It is the permanent memory of the computer where the contents cannot be
modified by an end user. ROM is a chip that is inserted into the motherboard. It is generally used to
store the Basic Input/Output system (BIOS), which performs the Power On Self Test (POST).
• RAM RAM is the read/write memory unit in
which the information is retained only as long
as there is a regular power supply. When the
power supply is interrupted or switched off, the
information stored in the RAM is lost. RAM is a
volatile memory that temporarily stores data and
applications as long as they are in use. When the
Integrated
use of data or the application is over, the content in chips
RAM is erased.
Fig. 1.13 RAM
• Cache memory Cache memory is used to store
the data and the related application that was last processed by the CPU. When the processor performs
processing, it first searches the cache memory and then the RAM, for an instruction. The cache
memory is always placed between CPU and the main memory of the computer system.
1.10 Computer Programming

Table 1.1 depicts some of the key differences between RAM and ROM:

TABLE 1.1

RAM ROM
It is a read/write memory It is a read only memory
It is volatile storage device It is a permanent storage device
Data is erased as soon as power supply is Data remains stored even after power supply
turned off has been turned off
It is used as the main memory of a computer It is used to store Basic input output system
system (BIOS).

Secondary Memory
Secondary memory represents the external storage devices that are connected to the computer. They provide
a non-volatile memory source used to store information that is not in use currently. A storage device is either
located in the CPU casing of the computer or is connected externally to the computer. The secondary storage
devices can be classified as:
• Magnetic storage device The magnetic storage
devices store information that can be read, erased
and rewritten a number of times. These include
floppy disk, hard disk and magnetic tapes.
• Optical storage device The optical storage devices
are secondary storage devices that use laser beams
to read the stored data. These include CD-ROM,
rewritable compact disk (CD-RW), and digital video
disks with read only memory (DVD-ROM). Fig. 1.14 Magnetic tape

Tracks
Sectors

Fig. 1.15 Magnetic disk


Introduction to Computers 1.11

Incident laser beam


Reflected laser beam

Fig. 1.16 Optical Disk

Reflective aluminium layer Magneto optical flim

Protective coating

Dielectric
layers

Laser beams

Lens
Substrate layer

Fig. 1.17 Magneto-optical disk


• Magneto-optical storage device The magneto-optical devices
are generally used to store information, such as large programs,
files and backup data. The end user can modify the information
stored in magneto-optical storage devices multiple times. These
devices provide higher storage capacity as they use laser beams
and magnets for reading and writing data to the device. Examples
of magneto-optical devices include Sony MiniDisc, Maxoptix T5-
2600, etc.
• Universal serial bus (USB) drive USB drive or commonly
known as pen drive is a removable storage device that is interfaced
on the USB port of a computer system. It is pretty fast and compact Fig. 1.18 USB drive
1.12 Computer Programming

in comparison to other storage devices like CD and floppy disk. One of the most important advantages
of a USB drive is that it is larger in capacity as compared to other removable storage devices. Off late,
it has become very popular amongst computer users.

1.3 PROGRAMMING LANGUAGES


The operations of a computer are controlled by a set of instructions (called a computer program). These
instructions are written to tell the computer:
1. what operation to perform
2. where to locate data
3. how to present results
4. when to make certain decisions
The communication between two parties, whether they are machines or human beings, always needs a
common language or terminology. The language used in the communication of computer instructions is
known as the programming language. The computer has its own language and any communication with the
computer must be in its language or translated into this language.
Three levels of programming languages are available. They are:
1. machine languages (low level languages)
2. assembly (or symbolic) languages
3. procedure-oriented languages (high level languages)

1.3.1 Machine Language


As computers are made of two-state electronic devices they can understand only pulse and no-pulse
(or ‘1’ and ‘0’) conditions. Therefore, all instructions and data should be written using binary codes
1 and 0. The binary code is called the machine code or machine language.
Computers do not understand English, Hindi or Tamil. They respond only to machine language. Added to
this, computers are not identical in design, therefore, each computer has its own machine language. (However,
the script 1 and 0, is the same for all computers). This poses two problems for the user.
First, it is difficult to understand and remember the various combinations of 1’s and 0’s representing
numerous data and instructions. Also, writing error-free instructions is a slow process.
Secondly, since every machine has its own machine language, the user cannot communicate with other
computers (If he does not know its language). Imagine a Tamilian making his first trip to Delhi. He would
face enormous obstacles as the language barrier would prevent him from communicating.
Machine languages are usually referred to as the first generation languages.

1.3.2 Assembly Language


The Assembly language, introduced in 1950s, reduced programming complexity and provided some
standardization to build an application. The assembly language, also referred to as the second-generation
programming language, is also a low-level language. In an assembly language, the 0s and 1s of machine
language are replaced with abbreviations or mnemonic code.
The main advantages of an assembly language over a machine language are:
• As we can locate and identify syntax errors in assembly language, it is easy to debug it.
• It is easier to develop a computer application using assembly language in comparison to machine
language.
• Assembly language operates very efficiently.
Introduction to Computers 1.13

An assembly language program consists of a series of instructions and mnemonics that correspond to a
stream of executable instructions. An assembly language instruction consists of a mnemonic code followed
by zero or more operands. The mnemonic code is called the operation code or opcode, which specifies the
operation to be performed on the given arguments. Consider the following machine code:
10110000 01100001
Its equivalent assembly language representation is:
mov al, 061h
In the above instruction, the opcode “move” is used to move the hexadecimal value 61 into the processor
register named ‘al’. The following program shows the assembly language instructions to subtract two
numbers:
ORG 500 /Origin of program is location 500
LDA SUB /Load subtrahend to AC
CMA /Complement AC
INC /Increment AC
ADD MIN /Add minuend to AC
STA DIF /Store difference
HLT /Halt computer
MIN, DEC 56 /Minuend
SUB, DEC -2 /Subtrahend
DIF, HEX 0 /Difference stored here
END /End of symbolic program
It should be noted that during execution, the assembly language program is converted into the machine
code with the help of an assembler. The simple assembly language statements had one-to-one correspondence
with the machine language statements. This one-to-one correspondence still generated complex programs.
Then, macroinstructions were devised so that multiple machine language statements could be represented
using a single assembly language instruction. Even today programmers prefer to use an assembly language
for performing certain tasks such as:
• To initialize and test the system hardware prior to booting the operating system. This assembly
language code is stored in ROM
• To write patches for disassembling viruses, in anti-virus product development companies
• To attain extreme optimization, for example, in an inner loop in a processor-intensive algorithm
• For direct interaction with the hardware
• In extremely high-security situations where complete control over the environment is required
• To maximize the use of limited resources, in a system with severe resource constraints

1.3.3 High-Level Languages


High level languages further simplified programming tasks by reducing the number of computer operation
details that had to be specified. High level languages like COBOL, Pascal, FORTRAN, and C are more
abstract, easier to use, and more portable across platforms, as compared to low-level programming languages.
Instead of dealing with registers, memory addresses and call stacks, a programmer can concentrate more on
the logic to solve the problem with help of variables, arrays or Boolean expressions. For example, consider
the following assembly language code:
LOAD A
ADD B
1.14 Computer Programming

STORE C
Using FORTRAN, the above code can be represented as:
C=A+B
The above high-level language code is executed by translating it into the corresponding machine language
code with the help of a compiler or interpreter.
High-level languages can be classified into the following three categories:
• Procedure-oriented languages (third generation)
• Problem-oriented languages (fourth generation)
• Natural languages (fifth generation)

1.3.4 Procedure-oriented Languages


High-level languages designed to solve general-purpose problems are called procedural languages or third-
generation languages. These include BASIC, COBOL, FORTRAN, C, C++, and JAVA, which are designed
to express the logic and procedure of a problem. Although, the syntax of these programming languages
is different, they use English-like commands that are easy to follow. Another major advantage of third-
generation languages is that they are portable. We can use the compiler (or interpreter) on any computer and
create the object code. The following program represents the source code in the C language:
if( n>10)
{
do
{
n++;
}while ( n<50);
}
The third generation programming languages are considered as domain-specific programming languages
because they are designed to develop software applications for a specific field. For example, the third
generation programming language, COBOL, was designed to solve a large number of problems specific to
the business field.

1.3.5 Problem-oriented Languages


Problem-oriented languages are used to solve specific problems and are known as the fourth-generation
languages. These include query Languages, Report Generators and Application Generators which have simple,
English-like syntax rules. Fourth-generation languages (4 GLs) have reduced programming efforts and overall
cost of software development. These languages use either a visual environment or a text environment for
program development similar to that of third-generation languages. A single statement in a fourth-generation
language can perform the same task as multiple lines of a third-generation language. Further, the programmer
just needs to drag and drop from the toolbar, to create various items like buttons, text boxes, labels, etc. Also,
the programmer can quickly create the prototype of the software application.
These languages are typically used in the WYSIWYG (What You See Is What You Get) environment
to facilitate faster and convenient application development. Visual Studio is one such environment that
encompasses a number of programming tools as well multiple programming language support to ensure
flexibility to the programmer during application development.

1.3.6 Natural Languages


Natural languages are designed to make a computer to behave like an expert and solve problems. The
programmer just needs to specify the problem and the constraints for problem-solving. Natural languages
Introduction to Computers 1.15

such as LISP and PROLOG are mainly used to develop artificial intelligence and expert systems. These
languages are widely known as fifth generation languages.
The programming languages of this generation mainly focus on constraint programming, which is
somewhat similar to declarative programming. It is a programming paradigm in which the programmer only
needs to specify the solution to be found within the constraints rather than specifying the method of finding
the desired solution
The programming languages of this generation allow the users to communicate with the computer system
in a simple and an easy manner. Programmers can use normal English words while interacting with the
computer system.

1.4 PROGRAMMING ENVIRONMENT


A programming environment comprises all those components that facilitate the development of a program.
These components are largely divided under two categories— programming tools and Application Programming
Interfaces (APIs). They are regarded as the building blocks of any programming environment.
An API can be defined as a collection of data structures, classes, protocols, and pre-defined functions
stored in the form of libraries. These libraries are included in the software packages of the programming
languages like C, C++, etc. An API makes the development task easier for the programmers, as in-built API
components are used again and again, ensuring reusability.
The software application which is used for the development, maintenance and debugging of a software
program is known as programming tool. A good programming tool ensures that the programming activities
are performed in an efficient manner. The following are some of the main categories of programming tools:
• Integrated Development Environment (IDE) It is the most commonly used tool that offers an
integrated environment to the programmers for software development. It contains almost all the
components for software development such as compiler, editor, debugger, etc.
• Debugging tool It is a specialized tool that helps the programmer to detect and remove bugs or
errors from a program.
• Memory usage tool As the name suggests, memory usage tool helps the programmer to manage the
memory resources in an efficient manner.

1.5 CREATING AND RUNNING PROGRAMS


A programmer should adopt standard methodologies and approaches to program development. Software or
program-development life cycle is one such standard methodology that is applicable to all types of program
development scenarios. It comprises of a number of interlinked phases with each phase serving a definite
purpose. We will study the program development life cycle in more detail in the next section.

1.5.1 Structured Programming


Another important program development approach is structured programming, which is a subset of one of the
key programming paradigms, i.e., procedural programming.
It helps in making a program easily understandable and debuggable. A program that is not based on the
structured programming approach is very difficult to maintain, debug and understand.
Structured programming approach mainly focuses on the order of execution of the statements within a
program. It suggests the use of sequential execution of statements in a program. Thus, structured programming
approach suggests the use of mainly three types of control structures—sequential, repetitive and selective.
1.16 Computer Programming

Further, it suggests avoiding the use of goto, break and continue statements in a program as all these are
unconditional branch statements.

1.5.2 System Development Tools


The successful development and execution of programs requires the usage of a number of tools. Some of
these typical system development tools are
• Language translators
• Linkers
• Debuggers
• Editors

Language Translators
• Assembler An assembler is a computer program that translates assembly language statements into
machine language codes. The assembler takes each of the assembly language statements from the source
code and generates a corresponding bit stream using 0’s and 1’s. The output of the assembler in the form of
sequence of 0’s and 1’s is called object code or machine code. This machine code is finally executed to obtain
the results.
A modern assembler translates the assembly instruction mnemonics into opcodes and resolves symbolic
names for memory locations and other entities to create the object code. Several sophisticated assemblers
provide additional facilities that control the assembly process, facilitate program development, and aid
debugging. The modern assemblers like Sun SPARC and MIPS based on RISC architectures, optimize
instruction scheduling to attain efficient utilization of CPU. The modern assemblers generally include a
macro facility and are called macro assemblers.
Assemblers can be classified as single-pass assemblers and two-pass assemblers. The single-pass
assembler was the first assembler that processed the source code once to replace the mnemonics with the
binary code. The single-pass assembler was unable to support advanced source-code optimization. As a
result, the two-pass assembler was developed that read the program twice. During the first pass, all the
variables and labels are read and placed into the symbol table. On the second pass, the label gaps are filled from
the table by replacing the label name with the address. This helps to attain higher optimization of the source
code. The translation process of an assembler consists of the following tasks:
• Replacing symbolic addresses like LOOP, by numeric addresses
• Replacing symbolic operation code by machine operation codes
• Reserving storage for the instructions and data
• Translating constants into their machine representation

• Compiler The compiler is a computer program that translates the source code written in a high-level
language into the corresponding object code of the low-level language. This translation process is called
compilation. The entire high-level program is converted into the executable machine code file. A program
that translates from a low-level language to a high-level one is a decompiler. Compiled languages include
COBOL, FORTRAN, C, C++, etc.
In 1952, Grace Hopper wrote the first compiler for the A-0 programming language. In 1957, John Backus
at IBM introduced the first complete compiler. With the increasing complexity of computer architectures
and expanding functionality supported by newer programming languages, compilers have become more
Introduction to Computers 1.17

and more complex. Though early compilers were written in assembly languages, nowadays it has become
common practice to implement a compiler in the language it compiles. Compilers are also classified as single-
pass compilers and multi-pass compilers. Though single-pass compilers are generally faster than multi-pass
compilers, for sophisticated optimization, multi-pass assemblers are required to generate high-quality code.

• Interpreter The interpreter is a translation program that converts each high-level program statement
into the corresponding machine code. This translation process is carried out just before the program statement
is executed. Instead of the entire program, one statement at a time is translated and executed immediately.
The commonly used interpreted language are BASIC and PERL. Although, interpreters are easier to create as
compared to compilers, the compiled languages can be executed more efficiently and are faster.

Linkers
Most of the high-level languages allow the developer to develop a large program containing multiple modules.
Linker arranges the object code of all the modules that have been generated by the language translator into
a single program. The execution unit of the computer system is incapable of linking all the modules at
the execution time and therefore, linker is regarded as one of the important software because of its ability
to combine all the modules into a single program. Linker assembles the various objects generated by the
compiler in such a manner that all the objects are accepted as a single program during execution. Linker
also includes the links of various objects, which are defined in the runtime libraries. In many cases, linker
inserts the symbolic address of the objects in place of their real address. Figure 1.19 illustrates the working
of a linker.

Debuggers
Debugger is the software that is used to detect the errors and bugs present in the programs. The debugger
locates the position of the errors in the program code with the help of what is known as the Instruction Set

Language Object Code


Module 1
Translator
Source Code

Language Object Code


Module 2
Translator
Source Code

. Executable
. Linker Program
.
Language Object Code
Module n
Translator
Source Code

Routine
Libraries

Fig. 1.19 Working of a linker


1.18 Computer Programming

Simulator (ISS) technique. ISS is capable of stopping the execution of a program at the point where an
erroneous statement is encountered.
Debugger is divided into two types, namely machine-level debugger and symbolic debugger. The machine-
level debugger debugs the object code of the program and shows all the lines where bugs are detected. On
the other hand, the symbolic debugger debugs the original code, i.e., the high-level language code of the
program. It shows the position of the bug in the original code of the program developed by the programmer.
While debugging a program, the debugger performs a number of functions other than debugging, such as
inserting breakpoints in the original code, tracking the value of specific variables, etc. In order to debug the
program, a debugger helps perform the following tasks:
• Step-by-step execution of a program
• Back tracking for checking the previous steps
• Stopping the execution of the program until the errors are corrected
Editors
Editor is a special program that allows the user to work with text in a computer system. It is used for the
documentation purposes and enables us to edit the information present in an existing document or a file. The
editor enables us to perform various editing operations such as copy, cut and paste while editing the text. On
the basis of the content edited by the editors, they are divided into the following categories:
• Text editor It is used to edit plain text. An operating system always includes a text editor for
updating the configuration files.
• Digital audio editor It is used to edit the information related to the audio components of a
multimedia application. These editors are used in audio applications where editing the music and the
sound signals is necessary.
• Graphics editor It is used to edit the information related to the graphical objects. These editors
are generally used in the multimedia applications where the user is working with multiple animation
objects.
• Binary file editor It is used to edit the digital data or the binary data, i.e., data having strings of 0s
and 1s.
• HTML editor It is used to edit the information included in the Web pages.
• Source code editor It is used to edit the source code of a program written in a programming
language such as C, C++ and Java.

1.5.3 Developing a Program


Developing a program refers to the process of writing the source code for the required application by following
the syntax and the semantics of the chosen programming language. Syntax and semantics are the set of rules
that a programmer needs to adhere while developing a program.
Before actually developing a program, the aim and the logic of the program should be very clear to the
programmer. Therefore, the first stage in the development of a program is to carry out a detailed study of
the program objectives. The objectives make the programmer aware of the purpose for which the program
is being developed. After ascertaining the program objectives, the programmer needs to list down the set of
steps to be followed for program development. This set of program development steps is called algorithm.
The programmer may also use a graphical model known as flowchart to represent the steps defined in the
program algorithm.
After the logic of the program has been developed either by an algorithm or a flowchart, the next step
is to choose a programming language for actual development of the program code. There are a number of
Introduction to Computers 1.19

factors that should be taken into consideration while selecting the target programming language, such as
performance and efficiency of the programming language, programmer’s prior experience with the language,
etc.
A programming language is typically bundled together with an IDE containing the necessary tools for
developing, editing, running and debugging a computer program. For instance, Turbo C is provided with a
strong and powerful IDE to develop, compile, debug and execute the programs.
Figure 1.20 shows the IDE of C language.

Fig. 1.20 The IDE of C Language.


Suppose we are required to develop a program for calculating the percentage of marks of two subjects
for student and display the result. The first step in the development of a program for this problem is the
preparation of an algorithm, as shown below:

Step 1 – Input the marks for first subject. (mark1)


Step 2 – Input the marks for second subject. (mark2)
Step 3 – Calculate the percentage.
percentage = (mark1 + mark2)/200*100
Step 4 – If percentage > 40
Step 5 – Display Pass
Step 6 – Else
Step 7 – Display Fail

Figure 1.21 shows the flowchart for the above algorithm.


1.20 Computer Programming

Start

Input Marks1, Marks2

Input Marks1, Marks2

Perc = (Total 2000)* 100

Is True Display ‘‘Pass’’


Perc > 40 ?

False
Display ‘‘Fail’’

End

Fig. 1.21 Flowchart for calculating the percentage of marks and displaying the result.
After developing the algorithm and flowchart, the actual development of the program can be started in the
source code editor of C language. The following code shows the C language program for calculating the
percentage of marks in two different subjects for a student.

#include<stdio.h>
#include<conio.h>
void main()
{
float mark1,mark2;
float percentage;
clrscr();
printf("\n Enter marks of first subject:");
scanf("\n %f", &mark1);
printf("\n Enter marks of second subject:");
scanf("\n %f", &mark2);
percentage =((mark1+mark2)/200)*100;
if(percentage>40)
Introduction to Computers 1.21

printf("\n The student is passed”);


else
printf("\n The student is failed”);
getch();
}

Figure 1.22 shows the program code in the source code editor of C language.

Fig. 1.22 Developing a program in the source code editor of C language.

1.5.4 Running a Program


After developing the program code, the next step is to compile the program. Program compilation helps
identify any syntactical errors in the program code. If there are no syntax errors in the source code, then the
compiler generates the target object code. It is the machine language code that the processor of the computer
system can understand and execute.
Once the corresponding object code or the executable file is built by the compiler, the program can be run
in order to check the logical correctness of the program and generate the desired output. The logical errors
also called semantic errors might cause the program to generate undesired results. Programming languages
provide various mechanisms such as exception handling for handling these logical errors. If the output
generated by the program corresponding to the given inputs matches with the desired result, then the purpose
of developing the program is served. Otherwise, the logic of the program should be checked again to obtain
the correct solution for the given problem.
Figure 1.23 shows the output of the program developed in C language.
1.22 Computer Programming

Fig. 1.23 Running a program.


The above figure shows the output generated by running the C program. We can run a program in C by either
selecting Run Æ Run or by pressing the Alt and F9 keys simultaneously.

1.6 SOFTWARE DEVELOPMENT METHOD


The entire process of software development and implementation involves a series of steps. Each successive
step is dependent on the outcome of the previous step. Thus, the team of software designers, developers and
operators are required to interact with each other at each stage of software development so as to ensure that
the end product is as per the client’s requirements. Figure 1.24 shows the various software development steps:

Analysing the
requirements

Feasibility
Analysis

Creating
the Design

Developing
code

Testing the
software

Deploying
the software

Maintaining
the software

Fig. 1.24 Software development steps


Introduction to Computers 1.23

1.6.1 Analysing the Requirements


In this step, the requirements related to the software, which is to be developed, are understood. Analysing
the requirements or requirement analysis is an important step in the process of developing a software. If the
requirements of the user are not properly understood, then the software is bound to fall short of the end user’s
expectations. Thus, requirement analysis is always the first step towards development of a software.
Software is abstract in nature; as a result, the users may not be able to provide the complete set of
requirements pertaining to the desired software during the requirement analysis stage. Thus, there should be
continuous interaction between the software development team and the end users. Moreover, the software
development team also needs to take into account the fact that the requirements of the users may keep changing
during the development process. Thus, proper analysis of user requirements is quite essential for developing
the software within a given timeframe. It will not only help in controlling the software development cost but
will also lead to faster and accurate development of a software.
The task of requirement analysis is typically performed by a business analyst. The person is a professional
in this field who understands the requirements of the novice end user, and documents and shares it with the
development team.

1.6.2 Feasibility Analysis


In this step, the feasibility of developing the software in terms of resources and cost is ascertained. In order
to determine the feasibility of software development, the existing system of the user is analysed properly.
Apart from studying the existing system, this step involves identifying the need of automation in the existing
system. The analysis done in this step is documented in a standard document called feasibility report, which
contains the observations and recommendations related to the task of software development. Some of the
important activities performed during the feasibility analysis stage are as follows:
• Determining development alternatives This activity involves searching for the different
alternatives that are available for the development of software. There are mainly four alternatives
available for the development of a software. The first alternative is to allow the existing system
to continue without developing a new software for automation. The second alternative can be to
develop the new software using specific programming languages such as Java, C++, Visual Basic etc.
The third alternative is to develop the software using the architectural technologies such as Java 2
Enterprise Edition (J2EE) and mainframe based with thin clients. The fourth development alternative
is to buy an already developed software along with its source code from the market and customise it
according to the client’s requirements.
• Analysing economic feasibility This activity involves determining whether the development of
a new software will be financially beneficial or not. This type of feasibility analysis is performed
to determine the overall profit that can be earned from the development and implementation of
the software. This feasibility analysis activity involves evaluating all the alternatives available for
development and selecting the one which is most economical.
• Assessing technical feasibility The technical feasibility assessment involves analysing various
factors such as performance of the technologies, ease of installation, ease of expansion or reduction
in size, interoperability with other technologies, etc. The technical feasibility activity typically
involves the study of the nature of technology as to how easily it can be learnt and the level of
training required to understand the technology. This type of feasibility assessment greatly helps in
selecting the appropriate technologies to be used for developing the software. The selection should
be made after evaluating the requirement specification of the software. In addition, the advantages
and disadvantages of each identified technology must also be evaluated during technical feasibility
assessment.
1.24 Computer Programming

• Analysing operational feasibility Operational feasibility assessment involves studying the software
on operational and maintenance fronts. The operational feasibility of any software is done on the basis
of several factors, such as:
– Type of tools needed for operating the software
– Skill set required for operating the software
– Documentation and other support required for operating the software

1.6.3 Creating the Design


After the feasibility analysis stage, the next step is creating the architecture and design of the new software.
This step involves developing a logical model or basic structure of the new software. For example, if the
new software is based on client–server technology then this step would involve determining and specifying
the number of tiers to be used in the client–server design. This step also involves documenting the varied
specifications pertaining to database and data structure design. The flow of the development process is mainly
illustrated in this stage using a special language known as Unified Modelling Language (UML). UML uses
pictorial representation methods for depicting the flow of data in the software. Some of the key features,
which are considered while designing a software, are:
• Extensibility The design of the software should be extensible so that it allows the addition of some
new options or modules in future. The architecture of the software should be flexible enough to not
get disturbed with the addition of new functionality.
• Modularity The software should be modular in nature so that its working and data flow can be
understood easily. Modularity also helps in parallel development of the various software modules,
which are later integrated into a single software product.
• Compatibility Software should run correctly in the existing system with an older version or
with other software. Thus, software should be compatible and work well in conjunction with other
software.
• Security Software must be able to control unauthorised access. While designing a new software, it
is ensured that there are proper security mechanisms incorporated in the product.
• Fault tolerance The software should be capable of handling exceptions or faults that may occur
during its operation. The software must have the capability to recover from failures.
• Maintainability The design of the software should be created in a simple manner with appropriate
details so that it is easy to maintain.

1.6.4 Developing Code


In this step, the code for the different modules of the new software is developed. The code for the different
modules is developed according to the design specifications of each module. The programmers in the software
development team use tools like compilers, interpreters and debuggers to perform tasks such as finding errors
in the code and converting the code into machine language for its execution. The code can be written using
programming languages such as C, C++ or Java. The choice of the programming language to be used for
developing the code is made on the basis of the type of software that is to be developed. There are certain key
points or conventions, which must be kept in mind while writing code; for instance:
• There should be proper indentation in the code.
• Proper naming conventions should be followed for naming the variables, methods and program
files.
• Proper comments should be included to ensure ease of understanding during maintenance.
Introduction to Computers 1.25

• The code for different modules of the new software must be simple so that it can be easily
understood.
• The code must be logically correct so as to minimise logical errors in the program.

1.6.5 Testing the Software


Testing is basically performed to detect the prevalence of any errors in the new software and rectify those
errors. One of the reasons for the occurrence of errors or defects in a new software is that the requirements of
the users or client were not properly understood. Another reason for the occurrence of errors is the common
mistakes committed by a programmer while developing the code. The two important activities that are
performed during testing are verification and validation. Verification is the process of checking the software
based on some pre-defined specifications, while validation involves testing the product to ascertain whether
it meets the user’s requirements. During validation, the tester inputs different values to ascertain whether the
software is generating the right output as per the original requirements. The various testing methodologies
include:
• Black box testing
• White box testing
• Gray box testing
• Nonfunctional testing
• Unit testing
• Integration testing
• System testing
• Acceptance testing

1.6.6 Deploying the Software


In this step, the newly developed and fully tested software is installed in its target environment. Software
documentation is handed over to the users and some initial data are entered in the software to make it
operational. The users are also given training on the software’s interface and its other functions.

1.6.7 Maintaining the Software


Once the software has been deployed successfully, a continuous support is provided to it for ensuring its
full-time availability. A corrupt file, a virus infection and a fatal error are some of the situations where the
maintenance personnel are asked to fix the software and bring it back to its normal functioning. Further, a
software may also be required to be modified if its environment undergoes a change. In order to successfully
maintain the software, it is required that it should have been properly documented at the time of its
development. This is because the maintenance person might not be the same who was originally involved in
the development of the software. Thus, a good code documentation serves vital for the maintenance person
to fix the software.

1.7 APPLYING SOFTWARE DEVELOPMENT METHOD


To understand how software development method is applied, consider a simple scenario where it is required
to convert the temperature given in Fahrenheit to its corresponding Celsius value.
Another Random Scribd Document
with Unrelated Content
—Bueno, bueno. Es asunto liquidado, y no hay que insistir en él.
María es muy buena y, además, muy generosa. Todo el dinero que le
he dado yo se lo ha entregado a Villarreal para sus deudas.
Unas semanas después estaba María de nuevo de regreso en
Bayona, muy descontenta de su viaje. A Villarreal, como al padre
Cirilo y a sus compañeros, que habían creído apoderarse del mando
y formar el Ministerio a su manera, después de aniquilar al partido
intransigente, les había salido mal la maniobra, y el despotismo
militar se entronizó bajo la dirección absoluta de Maroto.
Villarreal, el padre Cirilo y sus amigos quedaron de nuevo cesantes y
reducidos a la más absoluta impotencia.
Después de este último viaje, María volvió a otra casa de Bayona,
como señorita de compañía, y se dijo que estaba entregada a la
iglesia y que hacía con frecuencia ejercicios espirituales en la
Congregación de San Vicente de Paul.
XIV.

COMIENZA LA NUEVA VIDA

Se acercaba la época de mi matrimonio. Doña Mercedes aseguraba


que en llegando a la Corte conseguiría para mí un buen empleo.
Después de hablar con Aviraneta, quien me dijo que no tenía nada
que ver con el asunto, me entendí con Gomes Salcedo, y le cedí la
casa de comisión Etchegaray y Leguía por veinte mil francos.
Me despedí de mis amigos de Bayona y de Aviraneta.
—Bueno—me dijo éste—, seguiremos el procedimiento de
comunicarnos como antes, tú desde Madrid y yo desde Bayona.
—Mire usted—le dije—, no, don Eugenio. Me obligan a hacer otra
vida, necesito independencia y libertad en los movimientos. No
puedo perturbar la vida de estas dos mujeres. No quiero ser
conspirador.
—Bueno, bueno, está bien—replicó Aviraneta, ofendido.
—No creo que se deba usted ofender; yo le debo a usted todo lo
que soy, es cierto, pero también es cierto que ahora no voy a ser
solo, y no quiero dar a mi mujer una vida de sobresaltos, teniendo a
su marido vigilado y perseguido por la policía.
Me separé con tristeza de don Eugenio. ¿Qué iba a hacer? No podía
tomar otra determinación.
Unos días después, Corito y yo nos casamos y fuimos a Madrid.
María Cristina nos recibió, a mi suegra, a mi mujer y a mí, en
Palacio. Al mes tenía yo un alto empleo.

En Madrid hice relaciones y comencé una nueva vida, tan desligada


de la de Bayona, que ésta, en mi existencia, era como un prólogo
completamente aislado del resto de ella.
De mis conocidos en Bayona, volví a ver años después a muy pocos.
A Vinuesa le encontré y me llevó a su casa. No me hacía mucha
gracia hablar con su mujer. Vinuesa se lamentó con Aviraneta de que
yo no fuera a visitarle con frecuencia.
—Leguía no me quiere porque soy carlista—le dijo.
—Es un hombre seco y poco efusivo—le contestó don Eugenio.
Otro de mis conocidos, a quien vi en Madrid después de la guerra,
fué García Orejón. Era de los convenidos de Vergara, y le habían
dado un destino en la policía. Pensaba desempeñarlo durante cinco
o seis años, y luego, retirarse a una finca que había comprado cerca
de Córdoba.
Dentro de la burocracia fuí avanzando en mi carrera. Ya se me había
pasado el brío, la confianza en mi fuerza.
Comprendí cuán inferior era en este sentido a Aviraneta, que llevaba
más de treinta años en una constante aventura, y que aún no estaba
saciado. Me pareció que lo más propio para mí, desde entonces, era
ser espectador en las luchas políticas.
El decidirme a esta actitud hizo que fuera consultado y considerado
como un diplomático sagaz.
Sobre todo, hay que tener poco celo—decía Talleyrand a los amigos
que empleaba—. Es lo que hice yo: tener poco celo y dejarme llevar
por la corriente.

FIN DEL AMOR, EL DANDYSMO Y LA INTRIGA

Itzea, octubre, 1922.


ÍNDICE

PRIMERA PARTE
EXPERIENCIAS Y DESILUSIONES
Páginas.
En la Engadina. 7
I.— De Santander a Bayona. 11
II.— Aviraneta y yo. 16
III.— Proyectos. 21
IV.— Algo de mi infancia. 26
V.— La tienda de antigüedades. 30
VI.— Nuevas instrucciones. 35
VII.— La vida en Bayona. 41
VIII.— Sensibilidad patriótica. 48
IX.— Noticias de Aviraneta. 54
X.— Madama de Laussat. 57
XI.— Madama d'Aubignac. 60
XII.— La duquesa y su abate. 67
XIII.— La arbitrariedad. 74
SEGUNDA PARTE
DANDYSMO
En la frontera del Tirol. 79
I.— Una imprudencia. 80
II.— Desafío. 84
III.— Stratford Grain. 89
IV.— Las cartas de lord Chesterfield. 91
V.— Variedades sobre el dandysmo. 97
VI.— En Cambo. 102
VII.— Cita a la luz de la luna. 106
VIII.— Los políticos. 108
IX.— Nostalgias. 115
X.— Física. 118
XI.— Muñagorri y su gente. 121
XII.— Nueva tertulia. 126
XIII.— Vuelta por España. 130

TERCERA PARTE
NUEVOS CONOCIMIENTOS
En Saint-Moritz. 141
I.— París y Madrid. 143
II.— Los agentes secretos. 149
III.— La Reina. 155
IV.— Aquel Madrid. 157
V.— Vinuesa y su familia. 159
VI.— Aventura en Tolosa de Francia. 162
CUARTA PARTE
LOS PEONES DEL JUEGO
En Basilea. 167
I.— Los rivales. 170
II.— El Murciélago. 174
III.— Las letras S, T, U, V. 177
IV.— Valdés de los gatos. 181
V.— Bertache. 186
VI.— La letra Z. 192
VII.— Las bacantes vascas de Añoa. 197
VIII.— Emboscada. 203
IX.— Aviraneta, de nuevo. 205
X.— Apuros de Vinuesa. 211
XI.— Un proyecto atrevido. 215
XII.— El plan escrito. 221
XIII.— De Biriatu a Erlaiz. 228
XIV.— Rompimiento. 233
XV.— En el faubourg Saint-Germain. 236
XVI.— Los chapuzones de Valdés. 241
XVII.— Encuentro. 246
XVIII.— Un hombre de mala suerte. 251

QUINTA PARTE
LA AVENTURA PELIGROSA
En la costa cantábrica. 167
I.— María Luisa de Taboada. 261
II.— Petulancia contra petulancia. 265
III.— En Estella. 271
IV.— Los conjurados. 275
V.— Las tropas de Maroto. 278
VI.— La encerrona. 282
VII.— Explicaciones y amenazas. 285
VIII.— La escapatoria. 290
IX.— Tribulaciones. 295
X.— De Estella a San Juan de Luz. 300
XI.— Otra vez Vinuesa. 304
XII.— Enfermedad. 310
XIII.— La vuelta de María. 313
XIV.— Comienza la nueva vida. 316
*** END OF THE PROJECT GUTENBERG EBOOK EL AMOR, EL
DANDYSMO Y LA INTRIGA ***

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
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like