You are previewing C Programming for Scientists and Engineers with Applications.
O'Reilly logo
C Programming for Scientists and Engineers with Applications

Book Description

C is a favored and widely used programming language, particularly within the fields of science and engineering. C Programming for Scientists and Engineers with Applications guides readers through the fundamental, as well as the advanced concepts, of the C programming language as it applies to solving engineering and scientific problems. Ideal for readers with no prior programming experience, this text provides numerous sample problems and their solutions in the areas of mechanical engineering, electrical engineering, heat transfer, fluid mechanics, physics, chemistry, and more. It begins with a chapter focused on the basic terminology relating to hardware, software, problem definition and solution. From there readers are quickly brought into the key elements of C and will be writing their own code upon completion of Chapter 2. Concepts are then gradually built upon using a strong, structured approach with syntax and semantics presented in an easy-to-understand sentence format. Readers will find C Programming for Scientists and Engineers with Applications to be an engaging, user-friendly introduction to this popular language.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. Contents
  6. Preface
  7. Chapter 1 Introduction to Computers and Programming
    1. 1.1 Concept of Computers and Computer Systems
      1. 1.1.1 Hardware Components and Functions
      2. 1.1.2 Software Components and Functions
      3. 1.1.3 Integration of Hardware and Software
      4. 1.1.4 Review Questions
    2. 1.2 Modular Programming
      1. 1.2.1 Modular Design
      2. 1.2.2 Structure Charts
      3. 1.2.3 Functional Modules
      4. 1.2.4 Review Questions
    3. 1.3 Algorithms and Program Development
      1. 1.3.1 Concept of an Algorithm
      2. 1.3.2 Concept of Programs and Data
      3. 1.3.3 Procedure for Problem Analysis
      4. 1.3.4 Solution Design Methodology
      5. 1.3.5 Concept of Structured Programming
      6. 1.3.6 Review Questions
    4. 1.4 Program Processing
      1. 1.4.1 Program Coding
      2. 1.4.2 Program Compilation
      3. 1.4.3 Program Execution
      4. 1.4.4 Program Testing
      5. 1.4.5 Program Documentation
      6. 1.4.6 Review Questions
    5. 1.5 Program Processing Environment
      1. 1.5.1 Computer System Environment
      2. 1.5.2 Programming Environment
      3. 1.5.3 Review Questions
    6. 1.6 Samples of Algorithms
      1. 1.6.1 Resistance and Voltage of a Parallel Circuit
      2. 1.6.2 Volume of a Sphere
      3. 1.6.3 Square Root Approximation
      4. 1.6.4 Total Pressure of Gaseous Mixture
      5. 1.6.5 Mass Flow Rate of Air Through Pipes
    7. Chapter Summary
    8. Exercises
  8. Chapter 2 Basic Elements of the C Programming Language
    1. 2.1 Introduction to C
      1. 2.1.1 Structured Language
      2. 2.1.2 Procedural Language
      3. 2.1.3 Statically Typed Language
      4. 2.1.4 Review Questions
    2. 2.2 Constants and Variables
      1. 2.2.1 Character Set
      2. 2.2.2 Identifiers
      3. 2.2.3 Built-in Data Types
      4. 2.2.4 Derived Data Types
      5. 2.2.5 Pointer and Pointer Variables
      6. 2.2.6 Review Questions
    3. 2.3 Arithmetic Operations and Expressions
      1. 2.3.1 Arithmetic Operators and Operations
      2. 2.3.2 Arithmetic Expressions
      3. 2.3.3 Assignment Statement
      4. 2.3.4 Order of Evaluations
      5. 2.3.5 Use of Parentheses
      6. 2.3.6 Special Operators
      7. 2.3.7 Accuracy of Computation
      8. 2.3.8 C Libraries and Functions
      9. 2.3.9 Review Questions
    4. 2.4 Overview of Implementation
      1. 2.4.1 Formatting of Statements
      2. 2.4.2 Formatting of a Program
      3. 2.4.3 Data Design
      4. 2.4.4 Review Questions
    5. 2.5 First Complete Programs
      1. 2.5.1 Sample C Program
      2. 2.5.2 Slope of a Straight Line
      3. 2.5.3 Compression Stress in a Steel Column
      4. 2.5.4 Set of Simultaneous Equations
      5. 2.5.5 Area of a Scalene Triangle
      6. 2.5.6 Volume of a Sphere
    6. Chapter Summary
    7. Exercises
  9. Chapter 3 Input and Output
    1. 3.1 Input and Output Functions
      1. 3.1.1 Formatted Input and Output Functions
      2. 3.1.2 Standard Input Function
      3. 3.1.3 Standard Output Function
      4. 3.1.4 Review Questions
    2. 3.2 File Input and Output
      1. 3.2.1 Declaration of File Pointers
      2. 3.2.2 open and close Statements
      3. 3.2.3 Input from a Data File
      4. 3.2.4 Output to a Data File
      5. 3.2.5 Review Questions
    3. 3.3 Field Width Specification
      1. 3.3.1 Input Field Width Specification
      2. 3.3.2 Output Field Width Specification
      3. 3.3.3 Review Questions
    4. 3.4 Input and Output of Characters
      1. 3.4.1 Standard Input and Output
      2. 3.4.2 File Input and Output
      3. 3.4.3 Unformatted Input and Output
      4. 3.4.4 Review Questions
    5. 3.5 Sample Programs
      1. 3.5.1 Conversion from Polar to Cartesian Coordinates
      2. 3.5.2 Cost of a Steel Cage
      3. 3.5.3 Convection Heat Transfer
      4. 3.5.4 Air Conditioners Sales Report
      5. 3.5.5 Wavelength of an Electron
    6. Chapter Summary
    7. Exercises
  10. Chapter 4 Control Structures
    1. 4.1 Relational and Logical Operations
      1. 4.1.1 Relational Operators and Relational Expressions
      2. 4.1.2 Logical Operators and Logical Expressions
      3. 4.1.3 Review Questions
    2. 4.2 Selection Structures
      1. 4.2.1 Two-Way Selection Structures
      2. 4.2.2 Compound Conditions
      3. 4.2.3 Multiway Structures
      4. 4.2.4 Review Questions
    3. 4.3 Repetition Structures
      1. 4.3.1 Iterative Loops
      2. 4.3.2 Nested Iterative Loops
      3. 4.3.3 Conditional Loops
      4. 4.3.4 Review Questions
    4. 4.4 Stacking and Nesting of Control Structures
      1. 4.4.1 Control Structure Stacking
      2. 4.4.2 Nested Control Structures
      3. 4.4.3 Review Questions
    5. 4.5 Sample Problems and Programs
      1. 4.5.1 Impedance and Inductance of an Electrical Coil
      2. 4.5.2 Altitude of a Projectile
      3. 4.5.3 Shear Stress of a Metallic Member
      4. 4.5.4 Table of Periods of a Pendulum
      5. 4.5.5 Compression Stress and Strain in Steel Rods
      6. 4.5.6 Types of Triangles
    6. Chapter Summary
    7. Exercises
  11. Chapter 5 Modular Design and Function
    1. 5.1 Introduction to Modular Programming
      1. 5.1.1 Design of Modular Programs
      2. 5.1.2 Functional Modules in C
      3. 5.1.3 Review Questions
    2. 5.2 Functions
      1. 5.2.1 Function Declaration
      2. 5.2.2 Function Definition
      3. 5.2.3 Scope of Names
      4. 5.2.4 return Statement
      5. 5.2.5 Review Questions
    3. 5.3 Computation Functions
      1. 5.3.1 Passing Arguments by Value
      2. 5.3.2 Passing Arguments by Pointer
      3. 5.3.3 Review Questions
    4. 5.4 Input and Output Functions
      1. 5.4.1 Input Using Functions
      2. 5.4.2 Output Using Functions
      3. 5.4.3 Review Questions
    5. 5.5 Recursive Functions
      1. 5.5.1 Concept of Recursion
      2. 5.5.2 Relationship Between Iteration and Recursion
      3. 5.5.3 Review Questions
    6. 5.6 Sample Programs
      1. 5.6.1 Rocket Motor Thrust
      2. 5.6.2 Current in Series Circuit
      3. 5.6.3 Square Root Function
    7. Chapter Summary
    8. Exercises
  12. Chapter 6 Storage Classes
    1. 6.1 Scope of Variables
      1. 6.1.1 Block Structure
      2. 6.1.2 Global Scope and Block Scope
      3. 6.1.3 Scope of Access
      4. 6.1.4 Review Questions
    2. 6.2 Storage Classes in a Single File
      1. 6.2.1 Storage Class auto
      2. 6.2.2 Storage Class extern
      3. 6.2.3 Storage Class static
      4. 6.2.4 Storage Class register
      5. 6.2.5 Review Questions
    3. 6.3 Storage Classes in Multiple Files
      1. 6.3.1 Storage Class Extern
      2. 6.3.2 Review Questions
    4. 6.4 Sample Programs
      1. 6.4.1 Flow Through Pipes
      2. 6.4.2 Water Pressure
    5. Chapter Summary
    6. Exercises
  13. Chapter 7 One-Dimensional Arrays
    1. 7.1 One-Dimensional Arrays
      1. 7.1.1 Subscripts and Subscripted Variables
      2. 7.1.2 Declaration of Arrays
      3. 7.1.3 Initialization of Arrays
      4. 7.1.4 Review Questions
    2. 7.2 Input of One-Dimensional Arrays
      1. 7.2.1 Array Input
      2. 7.2.2 Input of Parallel Arrays
      3. 7.2.3 Review Questions
    3. 7.3 Output of One-Dimensional Arrays
      1. 7.3.1 Array Output
      2. 7.3.2 Output of Parallel Arrays
      3. 7.3.3 Review Questions
    4. 7.4 Manipulation of Arrays
      1. 7.4.1 Array Assignment
      2. 7.4.2 Array Arithmetic
      3. 7.4.3 Review Questions
    5. 7.5 Passing Arrays to Functions
      1. 7.5.1 Passing Fixed-Size Arrays
      2. 7.5.2 Passing Array Elements
      3. 7.5.3 Review Questions
    6. 7.6 Sample Programs
      1. 7.6.1 Reynolds Numbers
      2. 7.6.2 Stress and Strain
      3. 7.6.3 Standard Deviation
      4. 7.6.4 Maximum and Minimum Values
      5. 7.6.5 Sorting
      6. 7.6.6 Searching
      7. 7.6.7 Inventory of an Engineering Sales Company
    7. Chapter Summary
    8. Exercises
  14. Chapter 8 Multidimensional Arrays
    1. 8.1 Introduction to Two-Dimensional Arrays
      1. 8.1.1 Declaration Statement
      2. 8.1.2 Storage Allocation
      3. 8.1.3 Array Initialization
      4. 8.1.4 Review Questions
    2. 8.2 Input of Two-Dimensional Arrays
      1. 8.2.1 Standard Input
      2. 8.2.2 Input from a Data File
      3. 8.2.3 Review Questions
    3. 8.3 Output of Two-Dimensional Arrays
      1. 8.3.1 Standard Output
      2. 8.3.2 Output to a Data File
      3. 8.3.3 Review Questions
    4. 8.4 Manipulation of Arrays
      1. 8.4.1 Array Assignment
      2. 8.4.2 Array Arithmetic
      3. 8.4.3 Matrix Operations
      4. 8.4.4 Review Questions
    5. 8.5 Passing Arrays to Functions
      1. 8.5.1 Passing Fixed Size Arrays
      2. 8.5.2 Passing Array Elements
      3. 8.5.3 Review Questions
    6. 8.6 Higher-Dimensional Arrays
      1. 8.6.1 Declaration and Storage Allocation
      2. 8.6.2 Input of Three-Dimensional Arrays
      3. 8.6.3 Output of Three-Dimensional Arrays
      4. 8.6.4 Manipulation of Three-Dimensional Arrays
      5. 8.6.5 Review Questions
    7. 8.7 Sample Programs
      1. 8.7.1 Drag Force
      2. 8.7.2 Saddle Point
      3. 8.7.3 Computation of Pressure
      4. 8.7.4 Geometric Transformations
      5. 8.7.5 Inventory of Cars in the XYZ Dealership
    8. Chapter Summary
    9. Exercises
  15. Chapter 9 Characters and Strings
    1. 9.1 Introduction to Character Data
      1. 9.1.1 Declaration of Character Data
      2. 9.1.2 Initialization of Character Data
      3. 9.1.3 Input/Output of Character Data
      4. 9.1.4 Review Questions
    2. 9.2 Introduction to Strings
      1. 9.2.1 Declaration and Initialization of Strings
      2. 9.2.2 Storage of String Arrays
      3. 9.2.3 Input/Output of Character Strings
      4. 9.2.4 Review Questions
    3. 9.3 Strings and Functions
      1. 9.3.1 Passing Strings to Functions
      2. 9.3.2 Review Questions
    4. 9.4 String Library Functions
      1. 9.4.1 String Assignment
      2. 9.4.2 String Copy (strcpy)
      3. 9.4.3 String Concatenation (strcat)
      4. 9.4.4 String Comparison
      5. 9.4.5 String Length (strlen) and Other String Functions (strstr, strchr, and strrchr)
      6. 9.4.6 Review Questions
    5. 9.5 Sample Programs
      1. 9.5.1 Creating a List of Names from a File
      2. 9.5.2 Sorting a List of Names
      3. 9.5.3 Sequential Search of Parts List
    6. Chapter Summary
    7. Exercises
  16. Chapter 10 Pointers and Dynamic Storage
    1. 10.1 Concept of a Pointer
      1. 10.1.1 Pointers and Pointer Variables
      2. 10.1.2 One Level and Multilevel Indirection
      3. 10.1.3 Review Questions
    2. 10.2 Address and Pointer Arithmetic
      1. 10.2.1 Arithmetic Operations on Pointers
      2. 10.2.2 Dereferencing of Pointers
      3. 10.2.3 Review Questions
    3. 10.3 Pointers and Arrays
      1. 10.3.1 One-Dimensional Arrays
      2. 10.3.2 Increment and Decrement Operations
      3. 10.3.3 Two-Dimensional Arrays
      4. 10.3.4 Review Questions
    4. 10.4 Dynamic Storage and Arrays
      1. 10.4.1 One-Dimensional Arrays
      2. 10.4.2 Two-Dimensional Arrays
      3. 10.4.3 Review Questions
    5. 10.5 Character Strings and Pointers
      1. 10.5.1 Dynamic Storage of Character Strings
      2. 10.5.2 Passing Strings to Functions as Dynamic Arrays
      3. 10.5.3 Review Questions
    6. 10.6 Sample Programs
      1. 10.6.1 Tensile Stress
      2. 10.6.2 Days of Above Average Temperature
      3. 10.6.3 Sorting Dynamically Stored Character Strings
    7. Chapter Summary
    8. Exercises
  17. Chapter 11 Structures
    1. 11.1 Structures and Structure Variables
      1. 11.1.1 Declaration of Structures and Variables
      2. 11.1.2 Declaration of Arrays of Structure Variables
      3. 11.1.3 Structure Member and Pointer Operators
      4. 11.1.4 Definition of Structure Variables
      5. 11.1.5 Review Questions
    2. 11.2 Manipulation of Structures
      1. 11.2.1 Input/Output of Structure Variables
      2. 11.2.2 Arithmetic on Structure Variables
      3. 11.2.3 The typedef Statement and its Usage
      4. 11.2.4 Review Questions
    3. 11.3 Structures and Functions
      1. 11.3.1 Passing Structure Variables by Value
      2. 11.3.2 Returning Structure Variables
      3. 11.3.3 Passing Structure Variables by Pointer
      4. 11.3.4 Review Questions
    4. 11.4 Nested and Self-Referential Structures
      1. 11.4.1 Nested Structures
      2. 11.4.2 Self-Referential Structures
      3. 11.4.3 Review Questions
    5. 11.5 Union and Enumeration Data Types
      1. 11.5.1 Declaration of Union and Union Variables
      2. 11.5.2 Operations on Unions
      3. 11.5.3 Enumeration Data Type
      4. 11.5.4 Review Questions
    6. 11.6 Sample Programs
      1. 11.6.1 Parts Table
    7. Chapter Summary
    8. Exercises
  18. Appendix A
  19. Appendix B
  20. Appendix C
  21. Appendix D
  22. Index