Expressions and statements Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng Kung University Last updated: 5 October 2004 Chapter 4
Definition Statement End with a semicolon Whitespace Block and compound statement Block itself doesn’t end with a semicolon Expression Return a value
Operators Two categories Assignment == Mathematical +, - *, /, % Ex4-2 Division and modulus Modify Ex4-2 Combination of two categories Increment and decrement Prefix and postfix Ex4-3 Precedence and nesting parentheses
The nature of truth Relational operator Table 4.1 False: 0 True: others (1)
Logical statement if Single statement Block statement Indentation style Ex4-4 else Ex4-5 Nested statement of if and else Using braces EX4-7, Ex4-8
Logical operators Table 4.2 Precedence Truth and falsehood Conditional (ternary) operator ? : Ex4-9
Practice Write a program to solve the quadratic equation