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

Computer Programming 1st Edition E. Balagurusamy download

The document provides information on various computer programming books authored by E. Balagurusamy and others, including links for instant ebook downloads in multiple formats. It highlights the author's credentials and contributions to the field of Information Technology and Management. Additionally, the document outlines the content structure of the 'Computer Programming' book, detailing chapters and topics covered.

Uploaded by

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

Computer Programming 1st Edition E. Balagurusamy download

The document provides information on various computer programming books authored by E. Balagurusamy and others, including links for instant ebook downloads in multiple formats. It highlights the author's credentials and contributions to the field of Information Technology and Management. Additionally, the document outlines the content structure of the 'Computer Programming' book, detailing chapters and topics covered.

Uploaded by

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

Computer Programming 1st Edition E.

Balagurusamy
download

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

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


Get Your Digital Files Instantly: PDF, ePub, MOBI and More
Quick Digital Downloads: PDF, ePub, MOBI and Other Formats

Programming in ANSI C 6th Edition E. Balagurusamy

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

C Programming Data Structures 4th Edition E.


Balagurusamy

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

Computer Programming for Teens 1st Edition Mary E.


Farrell

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

Advanced Computer Programming in Python 1st Edition


Karim Pichara

https://ebookgate.com/product/advanced-computer-programming-in-
python-1st-edition-karim-pichara/
Computer Arithmetic Volume I Earl E Swartzlander

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

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/

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/

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/

Numerical Computer Methods Part E 1st Edition Michael


L. Johnson

https://ebookgate.com/product/numerical-computer-methods-
part-e-1st-edition-michael-l-johnson/
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.
Other documents randomly have
different content
inside of his mouth could be seen; he only smiled.” (Mishkāt, book xxii. ch.
vii.)

al-LAUḤU ʾL-MAḤFŪZ̤ ( ‫اللوح المحفوظ‬‎). “The preserved


tablet.”

In the Ḥadīs̤ and in theological works it is used to denote the tablet on


which the decrees of God were recorded with reference to mankind. In the
Qurʾān it only occurs once, when it refers to the Qurʾān itself. Sūrah lxxxv.
21, 22 : “It is a glorious Qurʾān written on the preserved table.” The plural
alwāḥ occurs in Sūrah vii. 142 , for the tables of the law given to Moses.

LAW, The. The words used by Muslims to express “the law,” are ash-

Sharīʿah (‫الشريعة‬‎ ‫الشرع‬‎


) and ash-Sharʿ ( ), the meaning of
which is “the way.” The compiler of the G͟ hiyās̤ u ʾl-Lug͟ hah defines it as
“the way or road in the religion of Muḥammad, which God has established
for the guidance of His people, both for the worship of God and for the
duties of life.” The term ash-Sharīʿah occurs once in the Qurʾān, Sūrah xlv.
17 : “We (God) put thee (Muḥammad) in the right way concerning the
affair.” The term ash-Shirʿah is almost obsolete in books on Muslim
theology, but it occurs once in the Qurʾān, Sūrah v. 52 : “To every one
have we given a right way.”

In the Traditions and theological works, the word ash-Sharʿ is generally


used to express the law of Muḥammad. The Hebrew ‫‏ּתֹוָר ה‬‎occurs in the
Qurʾān as Taurāt, and is always used for the law of Moses. [taurat.]

According to Muslim doctors, ash-Sharʿ, or “the Law,” may be divided into


five sections: Iʿtiqādāt, “belief”; Ādāb, “moralities”; ʿIbādāt, “devotions”;
Muʿāmalāt, “transactions”; and ʿUqūbāt, “punishments.”
(1) Iʿtiqādāt, embraces all that is contained in the six articles of the Muslim
faith, namely, Belief in (a) God; (b) His angels; (c) His Books; (d) His
Prophets; (e) The Day of Judgment; (f) The Decrees of God. This section of
Muslim law is termed ʿIlmu ʾl-ʿAqāʾid, or, “The Science of the Articles of
Belief,” and includes all branches of scholastic theology. The books chiefly
consulted on this subject in the present work are the Sharḥu ʾl-Muwāqif, by
Saiyid Sharīf-al-Jurjānī, and the Sharḥu ʾl-ʿAqāʾid, by Masʿūd Saʿdu ʾd-dīn
at-Taftāzānī.

(2) Ādāb embraces the consideration of all those moral excellences which
are enjoined in the Qurʾān and Traditions, as Ik͟ hlāṣ, “sincerity”;
Tawwakkul, “confidence in God”; Tawāz̤ uʿ, “humility”; Tafwīẓ,
“resignation”; Qaṣru ʾl-ʿAmal, “keeping down one’s expectation”; Zuhd fī
ʾd-dunyā, “renunciation of the world”; Naṣīḥah, “giving good counsel and
advice”; Qanāʿah, “contentment”; Sak͟ hāwah, “liberality”; Ḥubb, “love to
God and man”; Ṣabr, “patience”; &c. (See Majmaʿu ʾl-Biḥār, vol. ii. p.
422.)

(3) ʿIbādāt, includes all acts of devotion to God, such as are included in the
five pillars of practice: (a) Recital of the Creed; (b) Prayer; (c) Zakāt, or
“legal alms”; (d) Ṣaum, or “fasting”; (e) The pilgrimage to Makkah. It will
also embrace such religious acts as Jihād, or warfare for the propagation of
the religion of Islām.

(4) Muʿāmalāt, includes such duties as are required between man and man,
and is divided into Muk͟ hāṣamāt, “altercations”; Munākaḥāt, “nuptials”;
Amānāt, “securities.” Under these three heads are embraced all the various
sections of civil jurisprudence such as barter, sale, agency, larceny,
marriage, divorce, dower, partnership, claims, &c.

(5) ʿUqūbāt, denotes the punishments instituted in the Qurʾān and


Traditions, namely, (a) Qiṣāṣ, “retaliation”; (b) Ḥaddu ʾs-sariqah,
punishment for theft by the loss of a hand; (c) Ḥaddu ʾz-zināʾ, punishment
for fornication and adultery, stoning for a married person and one hundred
lashes for an unmarried person; (e) Ḥaddu ʾl-qazf, or punishment of eighty
lashes for slander; Ḥaddu ʾr-riddah, or punishment by death for apostasy;
Ḥaddu ʾsh-shurb, or punishment with eighty lashes for wine-drinking.

The two common divisions of Muḥammadan law are ʿIlmu ʾl-Kalām, or


ʿAqāʾid, embracing all matters of faith; and ʿIlmu ʾl-Fiqh, which includes
all matters of practice as distinguished from articles of faith.

Muslim law is also divided into two great distinctions of Mashrūʿ, “lawful,”
and G͟ hairu ʾl-mashrūʿ, “unlawful,” or, as it is expressed in Persian, Rawā
and Nārawā.

That which is lawful is graded into five classes. (1) Farẓ, that which is
proved beyond all doubt to have been enjoined either in the Qurʾān or in a
tradition of undoubted authority, and the denial or disobedience of which is
positive infidelity. (2) Wājib, that which is obligatory, but of which there is
some doubt whether or not it was enjoined in the Qurʾān or in a tradition of
undoubted authority. (3) Sunnah, that which was practised by Muḥammad;
(4) Mustāḥabb, that which Muḥammad and his Companions sometimes did
and sometimes omitted; (5) Mubāḥ, that which is desirable, but which may
be omitted without fear of sin.

Things which are unlawful are graded into three classes: (1) Mufsid, that
which is most vicious and corrupting, a mortal sin; (2) Ḥarām, that which is
distinctly forbidden; (3) Makrūh, that which is generally held to be unclean.

These distinctions of lawful and unlawful, with their various subdivisions,


apply to all branches of Muslim law, whether it relate to ordinary duties of
life, or of devotion to God.

It will be seen how important a place the example, practices, and sayings of
Muḥammad occupy in the moral law of Islām. This branch of Muslim law
is called as-Sunnah, or the custom of Muḥammad, and is distinguished as—

(1) Sunnatu ʾl-ʿfilī, that which Muḥammad himself did.

(2) Sunnatu ʾl-qaulī, that which Muḥammad said should be practised.


(3) Sunnatu ʾt-taqrīrī, that which was done in the presence of Muḥammad,
and which he appears to have sanctioned.

It is therefore a serious mistake to suppose that the Qurʾān contains all that
is esteemed necessary for faith and practice in Islām; the example of
Muḥammad is as binding upon the Muslim as any injunction contained in
the Qurʾān itself, for neither that which is Farẓ nor that which is Sunnah
can be omitted without sin.

The true origin and fountain of all law is the Qurʾān and the Traditions, and
no Muslim school of theology has ever rejected the Traditions. They are
binding upon Sunnī, and Shīʿah, and Wahhābī; the only difference between
the Sunnī and Shīʿah being that they receive different collections of
Traditions. The Wahhābīs receive those of the Sunnīs, and call themselves
Muḥaddis̤ in, or traditionists.

In addition to the Qurʾān and Ḥadīs̤ (or Traditions), both Sunnī and Shīʿah
Muslims acknowledge the concurrence of the learned, called Ijmāʿ, the
Shīʿahs believing that they still possess Mujtahids capable of giving an
infallible interpretation of the law; the Sunnīs, on the other hand, confessing
that, since the days of the four great doctors (Abū Ḥanīfah, Mālik, ash-
Shāfiʿī, and Ibn Ḥanbal), Ijmāʿ has not been possible; whilst the Wahhābīs
accept only the Ijmāʿ of those who conversed with the Prophet himself. The
fourth foundation of orthodoxy in both Sunnī and Shīʿah schools is the
system of interpretation called Qiyās, or ratiocination.

I. The Sunnīs all receive the same collections of traditions, especially those
which are known as the “six correct books,” the Ṣaḥīḥu ʾl-Buk͟ hārī, the
Ṣaḥīḥu Muslim, the Sunanu ʾt-Tirmiẓī, Sunanu Abī Dāʾūd, Sunanu an-
Nasafī, and Sunanu Ibn Mājah. The compilation by the Imām Mālik, which
is first in order of date, is also a collection of traditions of very great
authority. [traditions.]
These different sects of Sunnīs do not differ in uṣūl, or fundamentals of
religious belief, but in minor rules of practice, and in certain legal
interpretations; but being of different opinions and broaching in some
respects separate doctrines, four schools of jurisprudence have been
established, known as Ḥanafī, Shāfiʿī, Ḥanbalī, and Mālikī.

The differences amongst these four Sunnī schools are based either upon
different traditions or upon different interpretations of the same traditions,
also upon the various ways in which the liberty of qiyās, or ratiocination,
has been exercised. Consequently the number of works which have
appeared on the subjects of scholastic science and jurisprudence, has been
very great indeed.

We are indebted to Mr. Shama Churun Sircar, the learned and able Tagore
Professor of Law in Calcutta, for the following résumé of the principal
Sunnī writings on ash-Sharʿ.

“The chief works that treat generally of the doctrines of the four principal
sects of the Sunnís, are mentioned by Hájí Khalífah to be the Jámi-ul-
Mazáhib (Jāmiʿu ʾl-Maẕāhib), the Majmaa-ul-Khiláfíyat, the Yanábiya-ul-
Ahkám (Yanābīʿu ʾl-Aḥkām), the Uyúm, and the Zubdat-ul-Ahkám. The
Kanz-ud-Dakáïk (Kanzu ʾd-Daqāʾiq), by An-Nasafí, is a book of great
reputation, principally derived from the Wáfí; and containing questions and
decisions according to the doctrines of Abú-Hanífah, Abú-Yusuf, Imám
Muhammad, Zufar, Sháfií, Málik, and others. Many commentaries have
been written on the last mentioned work; the most famous of them is the
Bahr-ur-Ráïk (al-Baḥru ʾr-Rāʾiq), which may, indeed, almost be said to
have superseded its original, at least in India. The Bahr-ur-Ráïk is by Zainu-
ul-Aábidín Bin Nujaim-ul Misrí (Ibn Najīm), a.h. 970. The Multaka-al-
Abhár (Multaqa ʾl-Abḥār), by Shaikh Ibráhím Bin Muhammad al-Halabí,
who died a.h. 956, is a universal code of Muhammadan law. It gives the
different opinions or doctrines of Abú Hanífah, Málik, Sháfií, and Hanbal,
the chief Mujtahid Imáms and the founders of the four great sects of Sunnís,
and illustrates them by those of the principal jurisconsults of the school of
Abú Hanífah. It is more frequently referred to as an authority throughout
Turkey, than any other treatise on jurisprudence.
“The digests inculcating exclusively the doctrines of each of the said four
great sects are, indeed, numerous, though a very few of them which
maintain the doctrines of the Málikí, or Sháfií, or Hanbalí sects are used in
India. Digests written by Málik or any of his followers are scarcely found in
India.

“Of the digests maintaining the Málikí doctrines, two have lately appeared
in France (by M. Vincent, 1842; M. Perron, 1843). The first work of Sháfií,
entitled the Usúl (Uṣūl), or fundamentals, which contains the principles of
the Muhammadan civil and canon law, may be classed as a digest. The
Muk͟ htasar, the Mansúr, the Rasáïl-ul-Muatabirah (ar-Rasāʾilu ʾl-
Muʿtabarah), and the Kitáb-ul-Wasáïk, are amongst the other works written
by Abú Ibráhím Bin Yahiyá-al-Muzani, a distinguished disciple of Sháfií,
and a native of Egypt (a.h. 264), and are according to the doctrines of
Sháfií. The works by Ibnu Hambal and his followers are few in number, and
rare.

“The followers of the Hanífí sect, which obtains most commonly amongst
the Muhammadans of India, have, like others, divided their law into two
general branches or parts, respectively called the Fikah (law, religious and
secular), and Faráïz (the succession to, and division of, inheritance).

“The works which are on Fikah (Fiqh), and which are considered as the
chief authorities of the Hanífí sect, are the following:—Abú Hanífah’s own
digest of law, entitled the Fikah-ul-Akbar (al-Fiqhu ʾl-Akbar). This is the
first in rank, and has been commented upon by various writers, many of
whom are mentioned by Hájí Khalífah. The doctrines of that great lawyer,
however, are sometimes qualified or dissented from by his two famous
pupils, Abú Yusuf and Imám Muhammad. The work entitled Adab-ul-Kází,
which treats of the duties of a magistrate, is known to have been written by
Abú Yusuf. Save and except this, no other work appears to have been
composed by him. He, however, is said to have supplied his notes to his
pupil Imám Muhammad, who made use of them in the composition of his
own works. The works of Imám Muhammad are six in number, five of
which are, in common, entitled the Záhir-ur-Rawáyát (Z̤ āhiru ʾr-Rawāyāt,
conspicuous traditions or reports). They are: 1. The Jámi-ul-Kabír (al-
Jāmiʿu ʾl-Kabīr); 2. Jámi-us-Saghír (al-Jāmiʿu ʾṣ-Ṣag͟ hīr); 3. Mabsút fí
Farú-ul-Hanífiyát; 4. Ziyádát fí Farú-ul-Hanífiyát; and 5. Siyar al-Kabír wa
Saghír. The Nawádir, the sixth and last of the known compositions of Imám
Muhammad, though not so highly esteemed as the others, is still greatly
respected as an authority.

“The next authorities among the Hanafís, after the founder of their sect and
his two disciples, are the Imám Zufar Bin al-Hazíl who was chief judge at
Basrah, where he died (a.h. 158), and Hasan Bin Ziyád. These lawyers are
said to have been contemporaries, friends, and scholars of Abú-Hanífah,
and their works are quoted here as authorities for Abú Hanífah’s doctrines,
more especially when the two disciples are silent. The most celebrated of
the several treatises known by the name of Adáb-ul Kází was written by
Abú Bakr Ahmad Bin ʿUmar ul-Khassáf (a.h. 261). An abridgement of the
Hanafí doctrines, called the Mukhtasar ut-Tahaví, was written by Abú
Jaafar Ahmad Bin Muhammad at-Tahaví (a.h. 331), who wrote also a
commentary on the Jámi us-Saghír of Imám Muhammad.

“The Mukhtasar lil-Kudúrí, by Abú ul-Husain Ahmad Bin Muhammad al-


Kudúrí (a.h. 228) is among the most esteemed of the works which follow
the doctrines of Abú Hanífah. There is a well-known commentary on the
Mukhtasar lil-Kudúrí, entitled Al-Jauharat un-Nayyirah, which is
sometimes called Al-Jauharat ul-Munírah. The digest, entitled the Mabsút
(al-Mabsūt̤ ), was composed by Shams-ul-Aïmmah Abú Bakr Muhammad
as-Sarakhsi whilst in prison at Uʾzjand. This is a work of great extent and
authority. He was also the author of the most celebrated work entitled Al-
Muhít (al-Muḥīt̤ ), which is derived in a great measure from the Mabsút, the
Ziyádát, and the Nawádir of Imám Muhammad. The work entitled the
Muhít, by Burhán-ud-dín Mahmúd Bin Ahmad, already spoken of, is not so
greatly esteemed as the Muhít as-Sarakhsi (Muḥīt̤ u ʾṣ-Ṣarak͟ hsī). A
compendium of Al-Kudúrí’s Mukhtasar, which he entitled the Tuhfat-ul-
Fukahá (Tuḥfatu ʾl-Fuqahāʾ), was composed by Shaikh Alá-ud-dín
Muhammad as-Samarkandí. The work of Alá-ud-dín was commented upon
by his pupil Abú Bakr Bin Masuúd.
“There are several Arabic works on philosophical and theological subjects
which bear the name of Al-Hidáyah (the guide). The work entitled Al-
Hidáyah fí-al-Farú, or the guide in particular points, is a digest of law
according to the doctrines of Abú Hanífah and his disciples Abú Yusuf and
Imám Muhammad. The author of this work is Shaikh Burhán-ud-dín Alí
(a.h. 593), whose reputation as a lawyer was beyond that of all his
contemporaries. This Hidáyah is a commentary on the Badáya-ul-Mubtadá,
an introduction to the study of law, written by the same author in a style
exceedingly concise and close. In praise of the Hidáyah, Hájí Khalífah says,
‘It has been declared, like the Kurán, to have superseded all previous books
on the law; that all persons should remember the rules prescribed in it, and
that it should be followed as a guide through life.’ The Hidáyah has, besides
the Kifáyah, many other commentaries, as a work of so great celebrity and
authority is expected to have. The principal ones are the Ináyah (ʿInāyah),
the Niháyah, and the Fath-ul-Kabír.

“The name Ináyah, however, is given to two commentaries on the Hidáyah.


Of these, the one composed by Shaikh Kamál-ud-dín Muhammad Bin
Mahmúd, who died a.h. 786, is highly esteemed and useful. Supplying by
way of innuendoes what was omitted or left to implication, also expressing
what was understood in the Hidáyah, and explaining the words and
expounding the passages of the original by the insertion of explanatory
phrases, the author of the Ináyah has rendered the work such as to be
considered of itself one of his own principal works, with citations of
passages from the Hidáyah.

“The Niháyah is composed by Husám-ud-dín Husain Bin Alí, who is said to


have been a pupil of Burhán-ud-dín Alí. This is said to be the first
commentary composed on the Hidáyah; and it is important for having
added the law of inheritance to the Hidáyah, which treats only of the Fikah.
The commentary, entitled the Kifáyah, is by Imám-ud-dín Amír Kátib Bin
Amír Umar, who had previously written another explanatory gloss of the
same work, and entitled it the Gháyat-ul-Bayán. The Kifáyah was finished
a.h. 747, and, besides the author’s own observations, it gives concisely the
substance of other commentaries.
“The Fath-ul-Kabír lil-Aájiz ul-Fakír, by Kamál-ud-dín Muhammad as-
Siwásí, commonly called Ibnu Hammám, who died A.H. 861, is the most
comprehensive of all the comments on the Hidáyah, and includes a
collection of decisions which render it extremely useful. The short
commentary entitled the Fawáid, written by Hamíd-ud-dín Alí, Al-Buk͟ hárí,
who died a.h. 667, is said to be the first of all the commentaries on the
Hidáyah. The Wáfí, by Abú-ul-Barakát Abd ullah Bin Ahmad, commonly
called Háfiz-ud-dín an-Nasafí, and its commentary the Káfí, by the same
author, are works of authority. An-Nasafí died a.h. 710.

“The Vikáyah (al-Wiqāyah), which was written in the seventh century of the
Hijrah by Burhán ash-Shariyat Mahmúd, is an elementary work to enable
the student to study and understand the Hidáyah. The Vikáyah is printed,
and invariably studied, with its celebrated commentary, the Sharh ul-
Vikáyah, written by Ubaidullah Bin Masuúd, who died a.h. 745. The Sharh-
ul-Vikáyah contains the text of the Vikáyah, with a gloss most perspicuously
explanatory and illustrative; so much so, that those chapters of it which treat
of marriage, dower, and divorce, are studied in the Madrassahs of India in
preference to the Hidáyah itself. There are also other commentaries on the
Vikáyah, but not so useful as the above. On the Sharh-ul-Vikáyah, again,
there is an excellent commentary, entitled the Chalpí, written by Akhí Yusuf
Bin Juníd, who was one of the then eight professors at Constantinople. This
work was commenced to be written about a.h. 891, and completed a.h.
901; and the whole of it was published in Calcutta a.h. 1245, and extracts
therefrom have been printed.

“The Nikáyah (an-Niqāyah), another elementary law book, is the work of


the author of the Sharh-ul-Vikáyah. It is sometimes called the Mukhtasar ul-
Vikáyah, being, in fact, an abridgment of that work. Three comments on the
Nikáyah are much esteemed: they were written respectively by Abú ul-
Makárim Bin Abd-ullah (a.h. 907), Abú Alí Bin Muhammad al-Birjindí
(a.h. 935), and Shams ud-dín Muhammad al-Khurásání Al-Kohistání (a.h.
941). The last commentary is entitled the Jámi-ur-Rumúz (Jāmiʿu ʾr-
Rumūz), which is the fullest and the clearest of the lot, as well as one of the
most useful law books.
“The Ashbah wa an-Nazáïr (al-Ashbāh wa ʾn-Naz̤ āʾir) is also an
elementary work of great reputation. It was composed by Zain-al-Aábidín,
the author of the Bahr-ur-Ráïk already mentioned. Hájí Khalífah speaks of
this work in high terms, and enumerates several appendices to it that have
been composed at different times. The treatise on exegesis entitled the Núr-
ul-Anwár fí Sharah ul-Manár (Nūru ʾl-Anwār fī Sharḥi ʾl-Manār), by
Shaikh Jún Bin Abú Sayyid Al-Makkí (Shaik͟ h Jīwan ibn Abū Saʿīd), was
printed in Calcutta (a.d. 1819), and is frequently referred to as a book of
authority. A small tract on the sources of the Sharaa, entitled the Usúl-ush-
Sháshí, together with an explanatory commentary, was printed in
lithography, at Delhi, in the year a.d. 1847.

“The Tanvír-ul-Absár (Tanwīru ʾl-Abṣār), composed by Shaikh Shams-ud-


dín Muhammad Bin Abd-ullah-al-Ghazzí (a.h. 995), is one of the most
celebrated and useful books according to the Hanífí doctrines. This work
has many commentaries. One of them, entitled the Manh-ul-Ghaffár
(Manḥu ʾl-G͟ haffār), which is written by the author himself, is a work of
considerable extent.

“The Durr-ul-Mukhtár, which is another commentary on the Tanvír-ul-


Absár, is a work of great celebrity. This work was written (a.h. 1071) by
Muhammad Alá-ud-Dín Bin Shaikh Alí al-Hiskafí. Though a commentary,
it is virtually a digest, which of itself has several commentaries, the most
celebrated of them is the Tahtáví, a work used in India. Another
commentary on the Durr-ul-Mukhtár is the Radd-ul-Muhtár. This is a very
copious work, comprising an immense number of cases and decisions
illustrative of the principles contained in the principal work. The Durr-ul-
Mukhtár treats not only of the Fikah but also of the Faráïz. It is used by the
followers of the Hanífí doctrines whereever they are, but it is most highly
esteemed in Arabia, where it is studied and referred to in preference to other
books of law.

“Many works have been written according to the doctrines of Abú Hanífah
in the Turkish Empire, and are received there as authorities. The most
celebrated of those is the Multaka-ul-Abhár, by Shaikh Ibráhím Bin
Muhammad al-Halabí, the Durr-ul-Hukkám, by Mullah Khusrú, Kánún-
námai-Jazá, a tract on penal laws, &c.

“The treatises on the laws of inheritance, according to the doctrines of


Sháfií, are the Faráïz-ul-Mutawallí, by Abú Sayíd Abd-ur-Rahmán Bin
Mamun-ul-Mutawalli (who died a.h. 478), the Faráïz-ul-Mukuddasí, by
Abú-ul-Fazl Abd-ul-Malik Bin Ibráhím al-Hamadání Al-Mukuddasí, and
Abú Munsúr Abd-ul-Kahír Al-Baghdádí (who died respectively a.h. 489
and 429); Al-Faráïz-ul-Fazárí, by Burhán-ud-dín Abú Isháq Al-Fazárí,
commonly called Ibnu Firkáh (who died in a.h. 729), and Al-Faráïz ul-
Farikiyah, by Shams-ud-dín Muhammad Bin Killáyí (who died a.h. 777).

“Of the books on the law of inheritance according to the Hanífí doctrines,
the most celebrated, and the one invariably consulted in India, is the
Sirájiyyah (as-Sirājīyah), which is also called the Faráïz-us-Sajáwandí,
being, as it is, composed by Siráj-ud-Dín Muhammad bin Abd-ur-Rashíd
as-Sajáwandí. This work has been commented upon by a vast number of
writers, upwards of forty being enumerated in the Kashf-uz-Zunún by Hájí
Khalífah. The most celebrated of these commentaries, and the most
generally used to explain the text of the Sirájiyyah, is the Sharífiyyah (ash-
Sharīfīyah), by Sayyid Sharif Ali Bin Muhammad Al-Jurjání (who died a.h.
814).

“There is another kind of digest which treats of the Ilm-ul-Fatáwá (the


science of decisions). The works of this nature are also very numerous, and
are, for the most part, called Fatáwá (decisions), with the names of their
authors; and, though called Fatáwá, most of them contain also the rules of
law as well as legal decisions. Of those again, some treat of the Fikah alone,
others of the Faráïz (inheritance) also; some of them, moreover, treat of the
decisions of particular lawyers, or those found in particular books; others
treat of those which tend to illustrate the doctrines of the several sects;
whilst the rest of them are devoted to recording the opinions of learned
jurists.

“There are several collections of decisions, according to the doctrines of


Sháfií. The one most esteemed seems to be the Fatáwá Ibn us-Saláh, by
Abú Amru-Usmán Bin Abd-ur Rahmán ash-Sháhrazúrí, commonly called
Ibn us-Saláh, who died in a.h. 642. Ibnu Firkáh, the author of the Faráïz-ul-
Fazárí (a treatise on inheritance), also made a collection of decisions
according to the same doctrines, which is called, after his name, the
Fatáwá-i-Ibnu Firkáh.

“Of the Fatáwás of the Hanífí doctrines the following are generally known
in India. The Khulásat ul-Fatáwá (K͟ hulāṣatu ʾl-Fatāwā), by Imám Iftikhar-
ud-Dín Tahir Bin Ahmad Al-Bukhárí, who died a.h. 542, is a select
collection of decisions of great authority. The Zakhírat-ul-Fatáwá
(Ẕak͟ hīratu ʾl-Fatāwā), sometimes called the Zakhírat-ul-Burhániyah, by
Burhán-ud-Dín Bin Mázah al-Bukhárí, the author of the Muhít-ul-Burhání,
is also a celebrated, though not a large, collection of decisions, principally
taken from the Muhít. The Fatáwá-i-Kází Khán, by Imám Fakhr-ud-Dín
Hasan Bin Mansúr al-Uʾzjandí al-Farghání, commonly called Kází Khán,
who died a.h. 592, is a work held in very high authority. It is replete with
cases of common occurrence, and is, therefore, of great practical utility,
more especially as many of the decisions are illustrated by proofs and
reasoning on which they are founded. The two works entitled the Fusúl-ul-
Isturúshí and Fusúl-ul-Imádíah, were incorporated in a collection entitled
the Jámi-ul-Fusúlain, which is a work of some celebrity. It was compiled
by Badr-ud-Dín Muhammad, known by the name of Ibn-ul-Kází
Simáwanah (a.h. 823). The Fatáwá az-Zahíriyah, which contains decisions
collected partly from the Khizánat-ul-Wákiyát, was written by Jahír-ud-Dín
Abú Bakr Muhammad Bin Ahmad al-Bukhárí (a.h. 619). The Kuniyat-ul-
Muniyat is a collection of decisions of considerable authority by Mukhtár
Bin Mahmúd Bin Muhammad as-Záhidí Abú-ur-Rijá al-Ghazmíní,
surnamed Najm-ud-Dín, who died a.h. 658. An-Navaví, the author of the
biographical dictionary entitled the Tahzíb-ul-Asmá (Tahẕību ʾl-Asmāʾ),
who died a.h. 677, made a collection of decisions of some note, which is
called the Fatáwá an-Navaví. He also composed a smaller work of the same
nature, entitled al-Masáïl-ul-Muhimmat (ʿUyūn al-Masāʾili ʾl-Muhimmah),
arranged in the manner of question and answer. The Khizánat-ul-Muftiyín,
by Imám Husain Bin Muhammad as-Samaání, who completed his work in
a.h. 740, contains a large collection of decisions, and is a book of some
authority in India. The Khizánat-ul-Fatáwá, by Ahmad Bin Muhammad
Abú Bakr al-Hanafí, is a collection of decisions made towards the end of
the eighth century of the Hijrah, and comprises questions of rare
occurrence. The Fatáwá Tátár-Khániyah was originally a large collection
of Fatáwás, in several volumes, by Imám Aálim Bin Alá al-Hanafí, taken
from the Muhít-ul-Burhání, the Zakhírat, the Khániyah, and the Zahíriyah.
Afterwards, however, a selection was made from these decisions by Imám
Ibráhím Bin Muhammad al-Halabí, who died a.h. 956, and an epitome was
thus formed, which is in one volume, and still retains the title of Tátár-
Khániyah. The Fatáwá-i-Ahl-us-Samarkand, is a collection of the decisions
of those learned men of the city of Samarkand who are omitted, or lightly
passed over, in the Fatáwá-Tátár Khániyah and the Jámi-ul-Fusúlain, to
both of which works it may be considered a supplement. The Fatáwá az-
Zainíyah contains decisions by Zain ul-Aabidín Ibrahím Bin Nujaim al-
Misrí, the author of the Bahr-ur-Ráïk and the Ashbah wa-an-Nazáïr. They
were collected by his son Ahmad (about a.h. 970). The Fatáwá al-Ankiraví,
a collection of decisions of al-Ankiraví by Shaikh-ul-Islám Muhammad Bin
al-Husain, who died a.h. 1098, is a work of authority. The Fatáwá
Hammádiyah, though it seems to be a modern compilation, is a work of
considerable authority.

“Tipú Sultán ordered a collection of Fatáwás to be made in Persian by a


society of the learned of Mysore. It comprises three hundred and thirteen
chapters, and is entitled the Fatáwá-i-Muhummadí.

“Mr. Harrington, in his analysis (vol. i. 2nd ed.), mentions a few other
books of Fatáwá, viz. the Fatáwá Bazázíah, the Fatáwá Nakshbandiyah, the
Mukhtár-ul-Fatáwá, and the Fatáwá Karákhání. The last of these he
describes to be a Persian compilation, the cases included in which were
collected by Mullah Sadar-ud-Dín Bin Yákúb, and arranged some years
after his death by Kará Khán, in the reign of Sultán Alá-ud-Dín.

“The following works of the present class, published at Constantinople, and


containing decisions according to the doctrines of Abú Hanífah, may be
noticed. A collection of Fatwás in the Turkish and Arabic languages,
entitled the Kitáb fí al-Fikah al-Kadúsí, composed by Hafiz Muhammad
Bin Ahmad al-Kadúsí a.h. 1226. The Fatáwá-i-Abd-ur-Rahím Effendí, is a
collection of judgments pronounced at various times in Turkey, and
collected by the Muftí Abd-ur-Rahím. It was printed in the year 1827.
Dabagzadeh Nuamán Effendí is the author of a collection of six hundred
and seventy decisions, which is entitled the Tuhfat us-Sukúk, and was
published in the year 1832.

“The Jámi-ul-Ijáratín (Jāmiʿu ʾl-Ijārāt) is a collection of decisions relating


to the law of farming and the tenure of land, by Muhammad Aarif. It was
printed in the year 1836.

“A collection of Fatwás relating to leases was published at Constantinople


by M. D’Adelbourg, in the year 1838. Prefixed to this collection are the
principles of the law of lease, according to the Multaka; and it is followed
by an analytical table, facilitating reference to the various decisions.

“Of the Fatwás which treat both of the Fikah and Faráïz, two are most
generally used in India. These are the Fatáwá Sirájiyyah and Fatáwá
Alamgírí. The Fatáwá Sirájiyyah, with some principles, contains a
collection of decisions on cases which do not generally occur in other
books. The Fatáwá Alamgírí, with opinions and precepts of law, contains an
immense number of law cases. This work, from its comprehensive nature, is
applicable to almost every case that arises involving points of the Hanífí
doctrines. Although opinions of modern compilers are not esteemed as of
equal authority with those of the older writers on jurisprudence, yet being
composed by a great number of the most learned lawyers of the age, and by
order of the then greatest person of the realm, the Emperor Aurungzeb
Alamgír (by whose name the book is designated), the Fatáwá Alamgírí is
esteemed as a very high authority in India; and containing, as it does,
decisions on cases of any shape based upon unquestionable authorities, this
book is here referred to more frequently than any other work of a similar
nature, and has not up to this day been surpassed by any work, except
perhaps, by the Radd-ul-Muhtár, already spoken of. During the long rule of
the Muhammadans in India, the Fatáwá Alamgírí alone appears to have
been translated into Persian, by order of Zéb-un-nisá, daughter of the
Emperor Aurungzeb Alamgír. Since the establishment of the British
Government in India, the books of Jináyah and Hudúd from the Fatáwá
Alamgírí were translated into Persian, under the direction of the Council of
the College of Fort William in Calcutta, by the then Kází-ul-Kuzzát,
Muhammad Najm ud-Dín Khán, and were published in the year 1813,
together with a Persian treatise on Tázírát, by the same author.

“In the same year the book on Tázírát from the Durr-ul-Mukhtár was
translated, printed, and published, by Moulavi Muhammad Khalíl-ud-Dín,
under the orders of Mr. Harrington, the then Chief Judge of the late Sudder
Dewany Adawlut.

“The Hidáyah was translated into Persian by four of the most learned
Moulavis of that time and of this country (India). Unfortunately, however,
the learned translators have, in the body of the book, inserted many things
by way of explanatory remarks and illustrative expositions, instead of
subjoining them in the form of notes. Furthermore, they have, in a
considerable degree, deviated from the original. For all these reasons, we
are warranted to say, that the Persian version of the Hidáyah does not
represent a true picture of the original.

“Macnaghten’s Principles of Muhammadan Law were translated into Urdu


and lithographed, many years ago, in Delhi. Another translation of the same
work was made and published in Calcutta a few years ago.

“The work entitled the Bighyat-i-Báhis, by Al-Mutakannah, which is a tract


treating of Zaid’s system of Faráïz, was translated into English by Sir
William Jones. A translation of the Sirájiyyah also was made by Sir William
Jones, who at the same time made an abstract translation of its celebrated
commentary (the Sharífiyyah), with the addition of illustrations and
exemplifications from his own brain and pen. A translation of the selected
portions from the two books of the Fatáwá-i-Alamgírí, which comprise the
subject of sale, was published by Mr. Neil Baillie.

“The Persian version of the Hidáyah, already noticed, was, by order of


Warren Hastings, commenced to be translated into English by Mr. James
Anderson, but shortly after, he being engaged in an important foreign
employment, the translation was finished, and revised by his colleague, Mr.
Charles Hamilton. It is a matter of regret that the translation in question was
not executed from the original Hidáyah itself, instead of from its Persian
translation, which contains frequent explanatory remarks and illustrative
expositions interpolated in the book itself, instead of being subjoined by
way of notes. Added to this, the Persian translators have, in a considerable
degree, deviated from the original.

“Of the digests of Muhammadan law in English, the first appears to be the
chapter on criminal law of the Muhammadans as modified by regulations.
This is incorporated in Harrington’s Analysis of Bengal Regulations. An
abstract of Muhammadan law, which is from the pen of Lieutenant-Colonel
Vans Kennedy, will be found in the Journal of the Royal Asiatic Society.
‘This work,’ says Mr. Morley, ‘is well worthy the attention of the student.’
The work entitled the Principles and Precedents of Muhammadan Law,
written by Mr. (afterwards Sir) William Hay Macnaghten, is the clearest or
easiest, if not the amplest or sufficient, work on that law hitherto written in
English. Mr. Neil Baillie’s Muhammadan Law of Inheritance, according to
Abú Hanífah and his followers, with appendix containing authorities from
the original Arabic, is an excellent work of the kind. The treatise on
inheritance, gift, will, sale, and mortgage, compiled by Mr. F. E. Elberling,
a Danish judge at Serampore, in the year 1844, contains principles of
Muhammadan law, with those of the other laws, as used in India.

“In the year 1865, Mr. Neil Baillie, the author of the work already
mentioned, completed and published a digest of Muhammadan law on all
the subjects to which the Muhammadan law is usually applied by the
British Courts of Justice in India. It gives translations of almost all the
principles and some of the cases contained in the Fatáwá Alamgírí, the
great digest of Muhammadan law in India, and quotes occasionally other
available authorities. Being generally close to the original, and fully dealing
with the subjects it treats of, this work must be said to be authentic, as well
as the amplest of the digests of Muhammadan law hitherto written in
English according to the doctrines of the Hanífí sect.” (See the Tagore Law
Lectures, 1873, by Shama Churun Sircar; Thacker, Spink & Co., Calcutta.)
II.—The Shīʿahs, although they are divided amongst themselves into
numerous sects which differ from each other in various points of religious
belief, are unanimous in rejecting the collections of Traditions of the
Sunnīs. The Sunnīs arrogate to themselves the title of Traditionists, but this
does not imply that the Shīʿahs do not receive the Ḥadīs̤ , but merely that
they reject the “six correct books” of their opponents.

The works on Ḥadīs̤ compiled by the Shīʿahs are very numerous, and they
maintain that they have earlier and more authentic collections than those of
the Sunnīs. They say that in the time of al-Ḥasan and al-Ḥusain, a certain
person who was grandfather to ʿAbdu ʾllāh ibn ʿAlī ibn Abī Shuʿbah al-
Ḥalabī, collected traditions and gave them to his grandson for careful
record. This record was verified and corrected by Imām Jaʿfar aṣ-Ṣadīq. The
Sunnī doctor, Abū Ḥanīfah, was a pupil of this distinguished personage in
his earlier days, but afterwards separated from him and established a school
of his own.

There are four books of traditions, known as the Kutub-i-Arbaʿah, which


seem to be held in the same estimation by the Shīʿahs, as the six Ṣaḥīḥs of
the Sunnīs. They are entitled the Tahẕīb, the Istibṣār, the Kāfi, and Man lā
Yastaḥẓirah al-Faqīh. [traditions.]

Mr. Shama Churun Sircar, Tagore Professor of Law, has also reviewed the
Shīʿah, or Imamīyah, law books, and we are indebted to him for the
following résumé:—

“One of the earliest works on civil and criminal laws was written by
Abdullah Bin Alí al Halabí. But it does not appear that any of his legal
compositions are extant.

“A number of law-treatises of the present class was composed by Yunas Bin


Abd ur-Rahmán (already spoken of as a writer on traditions). The most
famous of these treatises is entitled the Jámi-ul-Kabír.
“Several works on law were written by Abú al-Hasan Alí Bin al-Hasan al-
Kumí, commonly called Ibnu Bábavaih, one of which works is entitled the
Kitábu ash-Sharáyah. The Maknaa fí al-Fikah (Maqnaʿ fī ʾl-Fiqh) is the
best known of the law books of the present class composed by Abú Jaafar.

“Abú Abdullah Muhammad an-Nuamání, surnamed the Shaikh Mufíd, and


Ibnu Muallim, a renowned Shíah lawyer, is stated to have written two
hundred works, amongst which one called the Irshád is well known. When
Shaikh Mufíd is quoted in conjunction with Abú Jaafar at-Túsí, they also
are spoken of as ‘the two Shaikhs’ (Shaikhain).

“The chief works on law, written by Abú Jaafar Muhammad at-Túsí (Abū
Jaʿfar Muḥammad at̤ -T̤ ūsī), are the Mabsút, the Khiláf, the Niháyah, and the
Muhít. These works are held in great estimation, and he is considered one of
the highest authorities in law. The Risálat-i-Jaafariyah is likewise a legal
treatise by at-Túsí, which is frequently quoted.

“The Sharáya ul-Islám, written by Shaikh Najm ud-dín Abú ul-Kásim


Jaafar Bin Muayyid al-Hillí, commonly called Shaikh Muayyid, is a work
of the highest authority, at least in India, and is more universally referred to
than any other Shíah law book, and is the chief authority for the law of the
Shíahs in India. A copious and valuable commentary upon the Sharáya ul-
Islám, entitled the Masálik ul-Afhám, was written by Zayin-ud-dín Alí as-
Sáilí, commonly called the ‘Shahíd-i-Sání’ (second martyr). There are two
other commentaries on the Sharáya ul-Islám, respectively entitled the
Madár ul-Ahkám and Jawáhir ul-Kalám, the latter of which was written by
Shaikh Muhammad Hasan an-Najafí.

“Of the works on jurisprudence written by Yahiyah Bin Ahmad al-Hillí,


who was celebrated for his knowledge of traditions, and is well known
amongst the Imámiyah sects for his works, the Jámi ash-Sharáya and the
Mudkhal dar Usúl-i-Fikah are held in the greatest repute.

“Of the numerous law books written by Shaikh Allámah Jamál-ud-dín


Hasan Bin Yusuf Bin al-Mutahhir al-Hillí, who is called the chief of the
lawyers of Hilliah, and whose works are frequently referred to as authorities
of undisputed merit, the most famous are the Talkhís ul-Marám, the Gháyit
ul-Ahkám, and the Tahrír ul-Ahkám, which last is a justly celebrated work.
The Mukhtalaf-ush-Shíah is also a well-known composition of this great
lawyer, and his Irshád ul-Azhán is constantly quoted as an authority under
the name of the Irshád-i-Allámáh.

“The Jámi-ul-Abbási is a concise and comprehensive treatise on Shíah law,


in twenty books or chapters. It is generally considered as the work of Bahá-
ud-dín Muhammad Aámilí, who died a.h. 1031.

“The Mafátíh, by Muhammad Bin Murtazá, surnamed Muhsan, and the


commentary on the book by his nephew, who was of the same name, but
surnamed Hádí, are modern works deserving of notice.

“The Rouzat ul-Ahkám, written in Persian by the third Mujtahid of Oudh,


consists of four chapters. The first of these is on Inheritance, which is
treated of therein most fully and perspicuously. This work was lithographed
at Lucknow, first in a.h. 1257, and again in a.h. 1264.

“A general digest of the Imámiyah law in temporal matters was compiled


under the superintendence of Sir William Jones. This book is composed of
extracts from the work called the Káfí, which is a commentary on the
Mafátíh, as well as from the Sharáya ul-Islám. The manuscript of this digest
still remains in the possession of the High Court of Judicature at Calcutta.

“The earliest treatises on the Faráïz, or Inheritance, of the Shíahs appear to


have been written by Abdul Azíz Bin Ahmad al-Azádí, and Abú
Muhammad al-Kindí, the latter of whom is said to have lived in the reign of
Hárún ur-Rashíd.

“A work on the law of inheritance, entitled the al-Ijáz fí al-Faráïz has been
left by Abú Jaafar Muhammad at-Túsí in addition to his general works on
the Kurán, the Hadís and jurisprudence.

“The best known and most esteemed works on the law of inheritance are the
Ihtijáj ush-Shíah, by Saád Bin Abd-ullah al-Asharí, the Kitáb ul-Mawáris,
by Abú al-Hasan Alí Bábavaih; the Hamal ul-Faráïz and the Faráïz ush-
Shariyah, by Shaikh Mufíd. The Sharáya ul-Islám, which, as already stated,
is one of the highest authorities on the Shíah law, contains also a chapter on
Inheritance.

Of all the above-mentioned books on civil and criminal laws, those that are
commonly referred to in India are the following: The Sharáya ul-Islám,
Rouzat-ul-Ahkám, Sharah-i-Lumá, Mafátíh, Tahrír, and Irshád ul-Azhán.

“Of the books on this branch of Muhammadan law, only that part of the
Sharáya ul-Islám which treats of the forensic law has been translated,
though not fully, by Mr. Neil Baillie. A considerable part of the digest
compiled under the superintendence of Sir William Jones (as already
noticed) was translated by Colonel Baillie, out of which the chapter on
Inheritance has been printed by Mr. Neil Baillie at the end of the second
part of his digest of Muhammadan law. Although the chapter above alluded
to is copious, yet it must be remarked that it is not so clear and useful as the
Sharáya-ul-Islám and Rouzat ul-Ahkám.” (See Tagore Law Lectures, 1874,
the Imámiyah Code, by Shama Churun Sircar; Thacker, Spink and Co.,
Calcutta.)

LAZ̤ Ā (‫لظى‬‎ ). “Fire, flame.” A division, or stage in hell, mentioned in


the Qurʾān, Sūrah lxx. 15 . Al-Bag͟ hawī, the commentator, says it is that
portion of hell which is reserved for the Christians who have not believed in
Muḥammad. [hell.]

LAZARUS. Arabic al-ʿĀzar ( ‫العازر‬‎ ). Not mentioned by name in the


Qurʾān, but Jalālu ʾd-dīn, in remarking on Sūrah iii. 43 : “I will bring the
dead to life by God’s permission,” says, amongst those whom Jesus raised
from the dead was al-ʿĀzar, who was his special friend and companion. The
account given by the commentators al-Kamālān of the raising of Lazarus, is
very similar to that given in the New Testament.

LEASE. Arabic ijārah ( ‫اجارة‬‎). [hire.]

LEBANON. Arabic Lubnān ( ‫لبنان‬‎ ). Not mentioned in the Qurʾān, but


tradition has it that Ishmael collected the stones for the Kaʿbah from five
sacred mountains, one of which was Mount Libanus. The followers of
Ismāʿīlu ʾd-Darāzī, known as the Druzes, a fanatical sect of Muslims, reside
on the southern range of the Lebanon chain. [druzes.]

LEGACY. [wills.]

‫ولد الحالل‬‎), “a legitimate child”;


LEGITIMACY. Waladu ʾl-ḥalāl (

waladu ʾz-zināʾ (‫ولد الزناء‬‎


), “an illegitimate child.”

The Muḥammadan law, unlike the law of England, makes legitimacy


depend, not merely upon the fact of the child being born in “lawful
wedlock,” but also conceived after lawful marriage.

According to the Sunnīs and Shīʿahs, and according to the teaching of the
Qurʾān itself, the shortest period of gestation recognised by law is six
months, and consequently a child born any time after six months from the
date of marriage has a claim to legitimacy. Amongst the Sunnīs, a simple
denial of the paternity of the child so born would not take away its status of
legitimacy. But the Shīʿahs hold that if a man get a woman with child and
then marry her, and she give birth to the child within six months after
marriage, legitimacy is not established.

As to the longest period of pregnancy, there are some strange rulings in


Muslim law. The Shīʿahs, upon the basis of a decision pronounced by ʿAlī,
recognise ten lunar months as the longest period of gestation, and this is
now regarded as the longest legal period by both Shīʿahs and Sunnīs. But
Abū Ḥanīfah and his two disciples, upon the authority of a tradition
reported by ʿĀyishah, regard two years as the longest period of gestation,
and the Imām ash-Shāfiʿī extended it to four, and the Imām Mālik to five
and even seven years! It is said these Sunnī doctors based their opinions on
the legendary birth of Zuhak Tāzi and others, who were born, so it is
related, in the fourth year of conception! But Muslim divines say that the
old jurisconsults of the Sunnī school were actuated by a sentiment of
humanity, and not by any indifference as to the laws of nature, their chief
desire being to prevent an abuse of the provisions of the law regarding
divorce and the disavowal of children. The general consensus of Muslim
doctors points to ten months as the longest period of pregnancy which can
be recognised by any court of justice.

[Under the old Roman law, it was ten months. In the Code Napoleon, article
312, it is three hundred days. Under the Jewish law, the husband had the
absolute right of disavowal. See Code Rabbinique, vol. ii. p. 63.]

The Muḥammadan law, like the English law, does not recognise the
legitimation of antenuptial children. Whereas, according to French and
Scotch law, such children are legitimated by the subsequent marriage of the
parents.

In Sunnī law, an invalid marriage does not affect the legitimacy of children
born from it. Nor does it in Shīʿah law; but the Shīʿah law demands proof
that such a marriage was a bona fide one, whilst the Ḥanafī code is not strict
on this point.
In the case of a divorce by liʿān [liʿan], the waladu ʾl-mulāʿanah, or “child
of imprecation,” is cut off from his right of inheritance from his father.

(See Syud Ameer Ali’s Personal Law of Muhammadans, p. 160; Fatāwā-i-


ʿAlamgīrī, p. 210; Sharāʾiʿu ʾl-Islām, p. 301.) [parentage.]

LETTERS. The letters of Muslims are distinguished by several


peculiarities, dictated by the rule of politeness. “The paper is thick, white,
and highly polished; sometimes it is ornamented with flowers of gold; and
the edges are always cut straight with scissors. The upper half is generally
left blank; and the writing never occupies any portion of the second side.
The name of the person to whom the letter is addressed, when the writer is
an inferior or an equal, and even in some other cases, commonly occurs in
the first sentence, preceded by several titles of honour; and is often written
a little above the line to which it appertains, the space beneath it in that line
being left blank; sometimes it is written in letters of gold, or red ink. A king,
writing to a subject, or a great man to a dependant, usually places his name
and seal at the head of his letter. The seal is the impression of a signet
(generally a ring, worn on the little finger of the right hand), upon which is
engraved the name of the person, commonly accompanied by the word ‘His
(i.e. God’s) servant,’ or some other words expressive of trust in God, &c. Its
impression is considered more valid than the sign-manual, and is
indispensable to give authority to the letter. It is made by dabbing some ink
on the surface of the signet, and pressing this upon the paper: the place
which is to be stamped being first moistened, by touching the tongue with a
finger of the right hand, and then gently rubbing the part with that finger. A
person writing to a superior, or to an equal, or even an inferior to whom he
wishes to show respect, signs his name at the bottom of his letter, next the
left side or corner, and places the seal immediately to the right of this; but if
he particularly desire to testify his humility, he places it beneath his name,
or even partly over the lower edge of the paper, which consequently does
not receive the whole of the impression.” (Lane’s Arabian Nights, vol. i. p.
23.)
LIʿĀN ( ‫لعان‬‎ ). Lit. “Mutual cursing.” A form of divorce which takes
place under the following circumstances. “If a man accuses his wife of
adultery, and does not prove it by four witnesses, he must swear before God
that he is the teller of truth four times, and then add: ‘If I am a liar, may
God curse me.’ The wife then says four times, ‘I swear before God that my
husband lies’; and then adds: ‘May God’s anger be upon me if this man be a
teller of truth.’ After this a divorce takes place ipso facto.” (See Sūratu ʾn-
Nūr, xxiv. 6 ; Mishkāt, book xiii. ch. xv.).

In the case of Liʿān, as in the other forms of divorce, the woman can claim
her dower.

Liʿān is not allowed in four cases, viz. a Christian woman married to a


Muslim, a Jewess married to a Muslim, a free woman married to a slave,
and a slave girl married to a free man.

The children of a woman divorced by Liʿān are illegitimate.

LIBĀS ( ‫لباس‬‎). [apparel.]

LIBERALITY. Arabic sak͟ hāwah ( ‫سخاوة‬‎), “hospitality”; infāq


( ‫انفاق‬‎), “general liberality in everything.”
Liberality is specially commended by Muḥammad in the Traditions:—
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