ebook img

Computing Fundamentals and C Programming PDF

628 Pages·2018·17.443 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computing Fundamentals and C Programming

Computing Fundamentals & C Programming Second Edition AAbboouutt tthhee AAuutthhoorr E Balagurusamy is presently the Chairman of EBG Foundation, Coimbatore. In the past he held the positions of member, Union Public Service Commission, New Delhi and Vice-Chancellor, Anna University, Chennai, Tamil Nadu. He is a teacher, trainer and consultant in the fi elds 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, Uttarakhand. His areas of interest include Object-Oriented Software Engineering, E-Governance: Technology Management, Business Process Re-engineering and Total Quality Management. A prolifi c writer, he has authored a large number of research papers and several books. His best-selling books, among others include: ∑ Programming in ANSIC, 7/e ∑ Fundamentals of Computers ∑ Programming in C#, 3/e ∑ Programming in Java, 5/e ∑ Object-Oriented Programming with C++, 6/e ∑ Programming in BASIC, 3/e ∑ Numerical Methods ∑ Reliability Engineering ∑ Introduction to Computing & Problem Solving using Python, 1e A recipient of numerous honour and awards, he has been listed in the Directory of Who’s Who of Intellectuals and in the Directory of Distinguished Leaders in Education. Computing Fundamentals & C Programming Second Edition E. Balagurusamy Chairman EBG Foundation Coimbatore McGraw Hill Education (India) Private Limited CHENNAI McGraw Hill Education Offi ces Chennai 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 444/1, Sri Ekambara Naicker Industrial Estate, Alapakkam, Porur, Chennai 600 116 Computing Fundamentals & C Programming, 2e Copyright © 2018, 2008 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 listings (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. 1 2 3 4 5 6 7 8 9 D102739 22 21 20 19 18 Printed and bound in India. Print Edition ISBN (13): 978-93-5260-416-6 ISBN (10): 93-5260-416-4 e-Edition ISBN (13): 978-93-5260-417-3 ISBN (10): 93-5260-417-2 Managing Director: Kaushik Bellani Director—Science & Engineering Portfolio: Vibha Mahajan Senior Portfolio Manager—Science & Engineering: Hemant K Jha Associate Portfolio Manager—Science & Engineering: Md. Salman Khurshid Content Development Lead: Shalini Jha Content Developer: Ranjana Chaube Production Head: Satinder S Baveja Copy Editor: Taranpreet Kaur Assistant Manager—Production: Anuj K Shriwastava General Manager—Production: Rajender P Ghansela Manager—Production: 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: Visit us at: www.mheducation.co.in Contents v CCoonntteennttss Preface xiii Visual Walkthrough xv 1. Understanding Fundamentals of the Computer 1 1.1 Introduction 1 1.2 Generations of Computers 2 1.3 Classifi cation of Computers 6 1.4 Basic Anatomy of a Computer System 7 1.5 Input Devices 8 1.6 Processor 9 1.7 Output Devices 10 1.8 Memory Management 11 1.9 Types of Computer Software 13 1.10 Overview of Operating System 14 1.11 MS Word 19 1.12 MS Excel System 21 1.13 MS Powerpoint System 22 1.14 Networking Concepts 23 1.15 Network Topologies 26 1.16 Network Protocols and Software 29 Learning Outcomes 31 Key Terms to Remember 32 Review Questions 33 Discussion Questions 42 2. Computing Concepts 45 2.1 Introduction 45 2.2 Decimal System 46 2.3 Binary System 47 2.4 Hexadecimal System 48 2.5 Octal System 49 2.6 Conversion of Numbers 50 2.7 Binary Arithmetic Operations 60 2.8 Logic Gates 68 2.9 Programming Languages 71 vi Contents 2.10 Translator Programs 74 2.11 Problem-Solving Techniques 75 2.12 Using the Computer 87 Learning Outcomes 87 Key Terms to Remember 88 Review Questions 89 Discussion Questions 92 3. Overview of C 93 3.1 Introduction 93 3.2 Importance of C 95 3.3 Sample Program 1: Printing a Message 95 3.4 Sample Program 2: Adding Two Numbers 98 3.5 Sample Program 3: Interest Calculation 99 3.6 Sample Program 4: Use of Subroutines 101 3.7 Sample Program 5: Use of Math Functions 102 3.8 Basic Structure of C Programs 104 3.9 Programming Style 105 3.10 Executing a ‘C’ Program 105 3.11 UNIX System 107 3.12 MS-DOS System 109 Learning Outcomes 109 Key Terms to Remember 110 Review Questions 110 Discussion Questions 111 Debugging Exercises 112 Programming Exercises 112 4. Constants, Variables and Data Types 115 4.1 Introduction 115 4.2 Character Set 115 4.3 C Tokens 117 4.4 Keywords and Identifi ers 118 4.5 Constants 118 4.6 Variables 122 4.7 Data Types 123 4.8 Declaration of Variables 126 4.9 Declaration of Storage Class 129 4.10 Assigning Values to Variables 130 4.11 Defi ning Symbolic Constants 135 4.12 Declaring a Variable as Constant 137 4.13 Declaring a Variable as Volatile 137 Learning Outcomes 137 Key Terms to Remember 138 Brief Cases 139 Review Questions 141 Discussion Questions 143 Contents vii Debugging Exercises 143 Programming Exercises 143 5. Operators and Expressions 145 5.1 Introduction 145 5.2 Arithmetic Operators 146 5.3 Relational Operators 148 5.4 Logical Operators 149 5.5 Assignment Operators 150 5.6 Increment and Decrement Operators 152 5.7 Conditional Operator 153 5.8 Bitwise Operators 153 5.9 Special Operators 154 5.10 Arithmetic Expressions 155 5.11 Evaluation of Expressions 156 5.12 Precedence of Arithmetic Operators 157 5.13 Some Computational Problems 159 5.14 Type Conversions in Expressions 161 5.15 Operator Precedence and Associativity 164 Learning Outcomes 167 Key Terms to Remember 167 Brief Cases 168 Review Questions 170 Discussion Questions 171 Debugging Exercises 173 Programming Exercises 174 6. Managing Input and Output Operations 177 6.1 Introduction 177 6.2 Reading a Character 178 6.3 Writing a Character 181 6.4 Formatted Input 182 6.5 Formatted Output 191 Learning Outcomes 198 Key Terms to Remember 198 Brief Cases 199 Review Questions 202 Discussion Questions 203 Debugging Exercises 205 Programming Exercises 205 7. Decision Making and Branching 207 7.1 Introduction 207 7.2 Decision Making with If Statement 208 7.3 Simple If Statement 208 7.4 The If.....Else Statement 212 7.5 Nesting of If....Else Statements 215 7.6 The Else If Ladder 218 viii Contents 7.7 The Switch Statement 222 7.8 The ? : Operator 226 7.9 The Goto Statement 230 Learning Outcomes 233 Key Terms to Remember 233 Brief Cases 234 Review Questions 238 Discussion Questions 239 Debugging Exercises 243 Programming Exercises 243 8. Decision Making and Looping 247 8.1 Introduction 247 8.2 The While Statement 249 8.3 The Do Statement 251 8.4 The For Statement 254 8.5 Jumps in Loops 264 8.6 Concise Test Expressions 271 Learning Outcomes 272 Key Terms to Remember 272 Brief Cases 273 Review Questions 280 Discussion Questions 280 Debugging Exercises 283 Programming Exercises 284 9. Array 287 9.1 Introduction 287 9.2 One-Dimensional Arrays 289 9.3 Declaration of One-dimensional Arrays 290 9.4 Initialization of One-dimensional Arrays 292 9.5 Two-Dimensional Arrays 298 9.6 Initializing Two-Dimensional Arrays 302 9.7 Multi-Dimensional Arrays 311 9.8 Dynamic Arrays 312 9.9 More About Arrays 312 Learning Outcomes 312 Key Terms to Remember 313 Brief Cases 313 Review Questions 326 Discussion Questions 328 Debugging Exercises 328 Programming Exercises 330 10. Character Arrays and Strings 334 10.1 Introduction 334 10.2 Declaring and Initializing String Variables 335 10.3 Reading Strings from Terminal 336 Contents ix 10.4 Writing Strings to Screen 343 10.5 Arithmetic Operations on Characters 347 10.6 Putting Strings Together 349 10.7 Comparison of Two Strings 350 10.8 String-Handling Functions 350 10.9 Table of Strings 357 10.10 Other Features of Strings 359 Learning Outcomes 359 Key Terms to Remember 359 Brief Cases 360 Review Questions 364 Discussion Questions 365 Debugging Exercise 366 Programming Exercises 366 11. User-Defined Functions 369 11.1 Introduction 369 11.2 Need for User-Defi ned Functions 370 11.3 A Multi-Function Program 370 11.4 Elements of User-Defi ned Functions 373 11.5 Defi nition of Functions 374 11.6 Return Values and their Types 376 11.7 Function Calls 377 11.8 Function Declaration 379 11.9 Category of Functions 380 11.10 Recursion 394 11.11 Passing Arrays to Functions 395 11.12 Passing Strings to Functions 399 11.13 The Scope, Visibility, and Lifetime of Variables 400 11.14 Multifi le Programs 410 Learning Outcomes 411 Key Terms to Remember 412 Brief Cases 413 Review Questions 416 Discussion Questions 417 Debugging Exercises 420 Programming Exercises 420 12. Structures and Unions 423 12.1 Introduction 423 12.2 Defi ning a Structure 424 12.3 Declaring Structure Variables 425 12.4 Accessing Structure Members 427 12.5 Copying and Comparing Structure Variables 430 12.6 Operations on Individual Members 432 12.7 Arrays of Structures 433 12.8 Arrays within Structures 435 x Contents 12.9 Structures within Structures 437 12.10 Structures and Functions 439 12.11 Unions and Structures 442 Learning Outcomes 445 Key Terms to Remember 446 Brief Cases 447 Review Questions 450 Discussion Questions 451 Debugging Exercises 454 Programming Exercises 454 13. Pointers 457 13.1 Introduction 457 13.2 Understanding Pointers 458 13.3 Accessing the Address of a Variable 460 13.4 Declaring Pointer Variables 461 13.5 Initialization of Pointer Variables 462 13.6 Accessing a Variable through its Pointer 463 13.7 Chain of Pointers 466 13.8 Pointer Expressions 466 13.9 Pointer Increments and Scale Factor 468 13.10 Pointers and Arrays 469 13.11 Pointers and Character Strings 472 13.12 Array of Pointers 474 13.13 Pointers as Function Arguments 475 13.14 Functions Returning Pointers 479 13.15 Pointers to Functions 479 13.16 Pointers and Structures 482 13.17 Troubles with Pointers 484 Learning Outcomes 485 Key Terms to Remember 486 Brief Cases 486 Review Questions 492 Discussion Questions 493 Debugging Exercises 494 Programming Exercises 495 14. File Management in C 497 14.1 Introduction 497 14.2 Defi ning and Opening a File 498 14.3 Closing a File 499 14.4 Input/Output Operations on Files 500 14.5 Error Handling During I/O Operations 506 14.6 Random Access to Files 509 14.7 Command Line Arguments 515 Learning Outcomes 518 Key Terms to Remember 518

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.