tailieunhanh - Lecture Computing for management - Chapter 26

After studying this chapter you will be able to understand: Learn about control structures; examine relational and logical operators; explore how to form and evaluate logical (boolean) expressions; discover how to use the selection control structures if, , and switch in a program; learn to use the assert function to terminate a program. | Booleans Lecture 26 CSE1301 Sem 2, 2003 Lecture 8: Booleans Summary of previous lecture In the previous lecture, we have been learnt, The if statement The else statement Cascaded if Nested if Switch statement Today’s Topics Boolean Type int as Boolean Boolean expressions Boolean Operators Precedence Common mistakes Boolean A special “type” with only two values: false and true. Used to implement conditions for selection and looping in an algorithm Boolean expressions represent statements which are either strictly true or strictly false We still have to cover Boolean Algebra --- History George Boole, 1815-1864 Initially self-guided studies of languages and philosophy With 16 assistant teacher at private school With 20 opened a school and taught himself mathematics Published in “Cambridge Mathematical Journal” with 24 The Mathematical Analysis of Logic was published in 1847 Casts logical reasoning in the form of algebra + is OR, * is AND 0 is FALSE, 1 is TRUE An Investigation of the Laws of Thought (1854) extends the algebra Type int as Boolean In C, integers are used as Booleans Integer value 0 is false. Any non-zero integer value is true. #include /* Test some Booleans. */ int main() { int whatever = 0; if (whatever) { printf(“Is that true, John?\n”); } else { printf(“No, Jane.\n”); } return 0; } Example: What is the output? #include /* Test some Booleans. */ int main() { int whatever = 1; if (whatever) { printf(“Is that true, John?\n”); } else { printf(“No, Jane.\n”); } return 0; } Example: What is the output? #include /* Test some Booleans. */ int main() { int whatever = -100; if (whatever) { printf(“Is that true, John?\n”); } else { printf(“No, Jane.\n”); } return 0; } Example: What is the output? #include /* Test some Booleans. */ int main() { int whatever = ’A’; if (whatever) { printf(“Is that true, John?\n”); } else { printf(“No, Jane.\n”); } return 0; } Example: What is the output? #include /* Test some . | Booleans Lecture 26 CSE1301 Sem 2, 2003 Lecture 8: Booleans Summary of previous lecture In the previous lecture, we have been learnt, The if statement The else statement Cascaded if Nested if Switch statement Today’s Topics Boolean Type int as Boolean Boolean expressions Boolean Operators Precedence Common mistakes Boolean A special “type” with only two values: false and true. Used to implement conditions for selection and looping in an algorithm Boolean expressions represent statements which are either strictly true or strictly false We still have to cover Boolean Algebra --- History George Boole, 1815-1864 Initially self-guided studies of languages and philosophy With 16 assistant teacher at private school With 20 opened a school and taught himself mathematics Published in “Cambridge Mathematical Journal” with 24 The Mathematical Analysis of Logic was published in 1847 Casts logical reasoning in the form of algebra + is OR, * is AND 0 is FALSE, 1 is TRUE An Investigation of the

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.