If Lesson 1 CS1313 Fall 2015 1 if Lesson 1 Outline 1.if Lesson 1 Outline 2.Absolute Value 3.Absolute Value Definition 4.Absolute Value Implementation 5.What.

Slides:



Advertisements
Similar presentations
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
Advertisements

Arithmetic Expressions Lesson #1 CS1313 Spring Arithmetic Expressions Lesson #1 Outline 1.Arithmetic Expressions Lesson #1 Outline 2.A Less Simple.
3 Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. Conditions can be formed using the.
CS0007: Introduction to Computer Programming
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.Repetition and Looping.
Introduction to C Programming
C Introduction Lesson CS1313 Spring C Introduction Lesson Outline 1.C Introduction Lesson Outline 2. hello_world.c 3.C Character Set 4.C is Case.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
C Introduction Lesson CS1313 Spring C Introduction Lesson Outline 1.C Introduction Lesson Outline 2. hello_world.c 3.C Character Set 4.C is Case.
Introduction to C Programming
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
Software Lesson #1 CS1313 Spring Software Lesson 1 Outline 1.Software Lesson 1 Outline 2.What is Software? A Program? Data? 3.What are Instructions?
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Idiotproofing Lesson CS1313 Spring Idiotproofing Outline 1.Idiotproofing Outline 2.Idiotproofing 3.Idiotproofing Quotes 4.An Idiotproof Website.
Introduction to C Programming
Programming Control Flow. Sequential Program S1 S2 S5 S4 S3 int main() { Statement1; Statement2; … StatementN; } Start End.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
If Lesson 3 CS1313 Spring if Lesson 3 Outline 1. if Lesson 3 Outline 2.Multiple, Related Conditions #1 3.Multiple, Related Conditions #2 4.Multiple,
User Defined Functions Lesson 2 CS1313 Spring User Defined Functions 2 Outline 1.User Defined Functions 2 Outline 2.Argument Order When Passing.
CECS 121 EXAM 1. /* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Array Lesson 1 CS1313 Spring Array Lesson 1 Outline 1.Array Lesson 1 Outline 2.Mean of a List of Numbers 3.mean: Declarations 4.mean: Greeting,
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
1 if and if-else statements. 2 Relational Operators x < y < is an operator x and y are its operands ( x < y ) is called a logical expression. Logical.
Program Looping Making Decisions Copyright © 2012 by Yong-Gu Lee
Array Lesson 2 CS1313 Spring Array Lesson 2 Outline 1.Array Lesson 2 Outline 2.Reading Array Values Using for Loop #1 3.Reading Array Values Using.
1 If statement and relational operators –, >=, ==, != Finding min/max of 2 numbers Finding the min of 3 numbers Forming Complex relational expressions.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
For Loop Lesson 1 CS1313 Spring for Loop Lesson 1 Outline 1. for Loop Lesson 1 Outline 2.A while Loop That Counts #1 3.A while Loop That Counts.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
A First Book of ANSI C Fourth Edition Chapter 4 Selection.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Week 8: Decisions Bryan Burlingame 21 October 2015.
Boolean Data Lesson CS1313 Fall Boolean Data Outline 1.Boolean Data Outline 2.Data Types 3.C Boolean Data Type: char or int 4.C Built-In Boolean.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
User Defined Functions Lesson 1 CS1313 Spring User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough.
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Controlling Program Flow with Decision Structures.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
CS1313: Arithmetic Expressions Lesson #2 CS1313 Spring Arithmetic Expressions Lesson #2 Outline 1.Arithmetic Expressions Lesson #2 Outline 2.Named.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 Lecture03: Control Flow 9/24/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Idiotproofing Lesson CS1313 Spring Idiotproofing Outline 1.Idiotproofing Outline 2.Idiotproofing 3.Idiotproofing Quotes 4.Idiotproofing Example.
Week 3 - Friday.  What did we talk about last time?  Preprocessor directives  Other C features  sizeof, const  ASCII table  printf() format strings.
 Real numbers representation - Floating Point Notation  First C Program  Variables Declaration  Data Types in C ◦ char, short, int, long, float, double,
CNG 140 C Programming (Lecture set 3)
‘C’ Programming Khalid Jamal.
for Loop 1 Outline for Loop 1 Outline for Loop
Operator Precedence Operators Precedence Parentheses () unary
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Idiotproofing Outline
while Loop Outline while Loop Outline while Loop Example #1
User Defined Functions 2 Outline
Structured Program
Nested if Lesson Outline
if Lesson 2 Outline The Meaning of else How Many Clauses Will Execute?
Relational, Logical, and Equality Operators
Computer programming Lecture 3.
ECE 103 Engineering Programming Chapter 22 Selection
Arithmetic Expressions Lesson #1 Outline
Presentation transcript:

if Lesson 1 CS1313 Fall if Lesson 1 Outline 1.if Lesson 1 Outline 2.Absolute Value 3.Absolute Value Definition 4.Absolute Value Implementation 5.What Does This Mean? 6.Branching with if 7.Example if Blocks 8.if Condition 9.if Block and Statement Terminators 10.if Block Indentation 11.if Flowchart 12.The Meaning of if #1 13.The Meaning of if #2 14.The Meaning of if #3 15.The Meaning of if #4 16.The Meaning of if #5 17.The Meaning of if #6 18.if Example #1 19.if Example #2 20.if Example Flowchart 21.Block Open/Close Comments for if Block 22.Boolean Expr Completely Parenthesized #1 23.Boolean Expr Completely Parenthesized #2 24.Boolean Expr Completely Parenthesized #3 25.Boolean Expr Completely Parenthesized #4 26.Boolean Expr Completely Parenthesized #5 27.BAD Condition #1 28.BAD BAD BAD Condition Example 29.GOOD Condition Example 30.Kinds of Statements Inside if Block 31.Statements Inside if Block 32.No Declarations Inside if Block 33.Absolute Value Example #1 34.Absolute Value Example #2 35.A More Complicated if Example #1 36.A More Complicated if Example #2 37.A More Complicated if Example #3 38.A More Complicated if Example #4 39.A More Complicated if Example Runs #1 40.A More Complicated if Example Runs #2 41.A More Complicated if Example Runs #3 42.Compound Statement a.k.a. Block #1 43.Compound Statement a.k.a. Block #2

if Lesson 1 CS1313 Fall Absolute Value Consider the function a(y) = | y | So we know that … a(-2.5)=|-2.5|=+2.5 a(-2)=|-2|=+2 a(-1)=||=+1 a(0)=|0|= 0 a(+1)=|+1|= a(+2)=|+2|= a(+2.5)=|+2.5|= …

if Lesson 1 CS1313 Fall Absolute Value Definition How is | y | defined? Well, you could always define it as the nonnegative square root of y 2 : But here’s another definition: if y is negative otherwise

if Lesson 1 CS1313 Fall Absolute Value Implementation Here’s an implementation of absolute value in C: if (y < 0) { absolute_value_of_y = -y; } /* if (y < 0) */ else { absolute_value_of_y = y; } /* if (y < 0)...else */ if y is negative otherwise

if Lesson 1 CS1313 Fall What Does This Mean? if (y < 0) { absolute_value_of_y = -y; } /* if (y < 0) */ else { absolute_value_of_y = y; } /* if (y < 0)...else */ 1.Evaluate the condition (y < 0), which is a Boolean expression, resulting in either true (1) or false (0). 2.If the condition evaluates to true, then execute the statement inside the if clause. 3.Otherwise, execute the statement inside the else clause.

if Lesson 1 CS1313 Fall Branching with if Branching is a way to select between possible sets of statements. In C, the most common kind of branching is the if block: if ( condition ) { statement1 ; statement2 ; … }

if Lesson 1 CS1313 Fall Example if Blocks if (a > b) { printf("Wow, a is greater than b!\n"); } /* if (a > b) */ if (my_height < your_height) { shortest_height = my_height; } /* if (my_height < your_height) */ if (entree_item_code == taco_code) { entree_price = taco_price; } /* if (entree_item_code == taco_code) */

if Lesson 1 CS1313 Fall if Condition if ( condition ) { statement1 ; statement2 ; … } The condition is a Boolean expression completely enclosed in parentheses. The condition is a Boolean expression, so it evaluates either to true ( 1 ) or to false ( 0 ). The Boolean expression that constitutes the condition MUST be completely enclosed in parentheses.

if Lesson 1 CS1313 Fall if Block and Statement Terminators if ( condition ) { statement1 ; statement2 ; … } The if statement is followed by a block open { rather than by a statement terminator (semicolon). Statements inside the if clause are followed by statement terminators (semicolons) as appropriate, just as if they were not inside the if clause. The block close } at the end of the if block ISN’T followed by a statement terminator (semicolon).

if Lesson 1 CS1313 Fall if Block Indentation if ( condition ) { statement1 ; statement2 ; … } Statements inside the if clause are indented additionally, beyond the indentation of the if statement and its associated block close. In CS1313, the statements inside the if clause are indented an additional 4 spaces beyond the if statement and its associated block close. In CS1313, you are ABSOLUTELY FORBIDDEN to use tabs for indenting in your source code.

if Lesson 1 CS1313 Fall if Flowchart statement_before; if ( condition ) { statement_inside1 ; statement_inside2 ; … } statement_after ; A diamond indicates a branch.

if Lesson 1 CS1313 Fall The Meaning of if #1 In my_number.c, we saw something like this: if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ What does this mean?

if Lesson 1 CS1313 Fall The Meaning of if #2 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ First, the condition ((users_number < minimum_number) || (users_number > maximum_number)) is evaluated, resulting in either true ( 1 ) or false ( 0 ). AGAIN: The condition is a Boolean expression completely enclosed in parentheses. Condition

if Lesson 1 CS1313 Fall The Meaning of if #3 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ Second, in the event that the condition evaluates to true ( 1 ), then the sequence of statement(s) inside the if clause – that is, between the block open of the if statement and the associated block close – are executed in order. Otherwise, these statements are skipped. Condition

if Lesson 1 CS1313 Fall The Meaning of if #4 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ Finally, regardless of whether the condition evaluates to true ( 1 ) or false ( 0 ), execution picks up at the next statement immediately after the block close of the if clause, and continues along from there. Condition

if Lesson 1 CS1313 Fall The Meaning of if #5 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ In the event that the condition evaluates to true ( 1 ) – that is, IF it’s the case that users_number is less than minimum_number OR it’s the case that users_number is greater than maximum_number, then the statement printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); is executed, in which case the output is: Hey! That's not between 1 and 10! Condition

if Lesson 1 CS1313 Fall The Meaning of if #6 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ On the other hand, if users_number lies between minimum_number and maximum_number – that is, if the condition evaluates to false ( 0 ) – then the printf statement is not executed, and therefore no output is produced by the if block. Condition

if Lesson 1 CS1313 Fall if Example #1 #include int main () { /* main */ const int computers_number = 5; int users_number; printf("Pick an integer:\n"); scanf("%d", &users_number); if (users_number < computers_number) { printf("That's unbelievable! Your number is\n"); printf(" less than mine!\n"); printf("Well, okay, maybe it’s believable.\n"); } /* if (users_number < computers_number) */ printf("And now I’m sick of you.\n"); printf("Bye!\n"); } /* main */

if Lesson 1 CS1313 Fall if Example #2 % gcc -o isless isless.c % isless Pick an integer: 6 And now I’m sick of you. Bye! % isless Pick an integer: 5 And now I’m sick of you. Bye! % isless Pick an integer: 4 That's unbelievable! Your number is less than mine! Well, okay, maybe it’s believable. And now I’m sick of you. Bye!

if Lesson 1 CS1313 Fall if Example Flowchart printf("Pick an integer:\n"); scanf("%d", &users_number); if (users_number < computers_number) { printf("That's unbelievable! Your number is\n"); printf(" less than mine!\n"); printf("Well, okay, maybe it’s believable.\n"); } /* if (users_number < computers_number) */ printf("And now I’m sick of you.\n"); printf("Bye!\n");

if Lesson 1 CS1313 Fall Block Open/Close Comments for if Block if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ NOTICE: The block open of this if block doesn’t have a comment on the same line. The block close of this if block does have a comment on the same line, and that comment contains the if statement, or a truncated version of it, EXCLUDING its block close.

if Lesson 1 CS1313 Fall Boolean Expr Completely Parenthesized #1 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ The condition ((users_number < minimum_number) || (users_number > maximum_number)) is a Boolean expression completely enclosed in parentheses. How do we know this? Condition

if Lesson 1 CS1313 Fall Boolean Expr Completely Parenthesized #2 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ First, this subexpression (users_number < minimum_number) is a Boolean expression, specifically a relational expression, so it evaluates to a Boolean value – true ( 1 ) or false ( 0 ). Condition

if Lesson 1 CS1313 Fall Boolean Expr Completely Parenthesized #3 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ Second, this subexpression (users_number > maximum_number) is a Boolean expression, specifically a relational expression, so it evaluates to a Boolean value – true ( 1 ) or false ( 0 ). Condition

if Lesson 1 CS1313 Fall Boolean Expr Completely Parenthesized #4 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ The condition (users_number < minimum_number) || (users_number > maximum_number) is a pair of Boolean subexpressions, specifically relational expressions, joined by a Boolean operation, OR ( || ). So the expression as a whole is a Boolean expression. Condition

if Lesson 1 CS1313 Fall Boolean Expr Completely Parenthesized #5 if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ The condition ((users_number < minimum_number) || (users_number > maximum_number)) is a pair of Boolean subexpressions, specifically relational expressions, joined by a Boolean operation, OR ( || ), then enclosed in parentheses. So: The condition is a Boolean expression completely enclosed in parentheses. Condition

if Lesson 1 CS1313 Fall BAD Condition #1 if (users_number < minimum_number) || (users_number > maximum_number) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ What if the condition (users_number < minimum_number) || (users_number > maximum_number) were a Boolean expression but were not completely enclosed in parentheses? The compiler would treat this as an error! It would be WRONG WRONG WRONG. Condition

if Lesson 1 CS1313 Fall BAD BAD BAD Condition Example % cat condnotenclosed.c #include int main () { /* main */ const int minimum_number = 1; const int maximum_number = 10; int users_number = 0; if (users_number < minimum_number) || (users_number > maximum_number) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if (users_number < minimum_number) ||... */ } /* main */ % gcc -o condnotenclosed condnotenclosed.c condnotenclosed.c: In function main: condnotenclosed.c:9: error: expected expression before || token Notice that the compiler is VERY UNHAPPY.

if Lesson 1 CS1313 Fall GOOD Condition Example % cat condenclosed.c #include int main () { /* main */ const int minimum_number = 1; const int maximum_number = 10; int users_number = 0; if ((users_number < minimum_number) || (users_number > maximum_number)) { printf("Hey! That's not between %d and %d!\n", minimum_number, maximum_number); } /* if ((users_number < minimum_number) ||... */ } /* main */ % gcc -o condenclosed condenclosed.c % condenclosed Hey! That's not between 1 and 10! Notice that the compiler is now HAPPY!

if Lesson 1 CS1313 Fall Kinds of Statements Inside if Block Between the if statement’s block open and the associated block close, there can be any kind of executable statements, and any number of them. For example: printf statements; scanf statements; assignment statements; if blocks. There are several other kinds of executable statements that can occur inside an if block, some of which we’ll learn later in the semester.

if Lesson 1 CS1313 Fall Statements Inside if Block In the event that the if condition evaluates to true ( 1 ), then the statements inside the if block will be executed one by one, in the order in which they appear in the if block.

if Lesson 1 CS1313 Fall No Declarations Inside if Block Notice that an if block SHOULDN’T contain declaration statements, because the if statement is an executable statement, and ALL declarations MUST come before ANY executable statements.

if Lesson 1 CS1313 Fall Absolute Value Example #1 % cat absval.c #include int main () { /* main */ float input_value, output_value; printf("I'm going to calculate the absolute\n"); printf(" value of a value that you input.\n"); printf("Please input the value.\n"); scanf("%f", &input_value); if (input_value < 0) { output_value = -input_value; } /* if (input_value < 0) */ else { output_value = input_value; } /* if (input_value < 0)...else */ printf("The absolute value of %f is %f.\n", input_value, output_value); } /* main */

if Lesson 1 CS1313 Fall Absolute Value Example #2 % gcc –o absval absval.c % absval I'm going to calculate the absolute value of a value that you input. Please input the value. 5 The absolute value of is % absval I'm going to calculate the absolute value of a value that you input. Please input the value. -5 The absolute value of is

if Lesson 1 CS1313 Fall A More Complicated if Example #1 #include int main () { /* main */ const int int_code = 1; const int float_code = 2; const int program_failure_code = -1; float float_input_value, float_output_value; int int_input_value, int_output_value; int data_type_code;

if Lesson 1 CS1313 Fall A More Complicated if Example #2 printf("I’m going to calculate the"); printf(" absolute value\n"); printf(" of a number that you input.\n"); printf("Would you like to input "); printf("an int or a float?\n"); printf(" (Enter %d for an int ", int_code); printf("or %d for a float.)\n", float_code); scanf("%d", &data_type_code); if ((data_type_code != int_code) && (data_type_code != float_code)) { printf("ERROR: I don’t recognize the "); printf("data type code %d.\n", data_type_code); exit(program_failure_code); } /* if ((data_type_code != int_code)... */ Idiotproofing

if Lesson 1 CS1313 Fall A More Complicated if Example #3 if (data_type_code == int_code) { printf("Please input the int.\n"); scanf("%d", &int_input_value); if (int_input_value < 0) { int_output_value = -int_input_value; } /* if (int_input_value < 0) */ else { int_output_value = int_input_value; } /* if (int_input_value < 0)...else */ printf("The absolute value of "); printf("%d is %d.\n", int_input_value, int_output_value); } /* if (data_type_code == int_code) */

if Lesson 1 CS1313 Fall A More Complicated if Example #4 if (data_type_code == float_code) { printf("Please input the float.\n"); scanf("%f", &float_input_value); if (float_input_value < 0) { float_output_value = -float_input_value; } /* if (float_input_value < 0) */ else { float_output_value = float_input_value; } /* if (float_input_value < 0)...else */ printf("The absolute value of "); printf("%f is %f.\n", float_input_value, float_output_value); } /* if (data_type_code == float_code) */ } /* main */

if Lesson 1 CS1313 Fall A More Complicated if Example Runs #1 % gcc -o absvalbytype absvalbytype.c % absvalbytype I’m going to calculate the absolute value of a number that you input. Would you like to input an int or a float? (Enter 1 for an int or 2 for a float.) 0 ERROR: I don’t recognize the data type code 0.

if Lesson 1 CS1313 Fall A More Complicated if Example Runs #2 % absvalbytype I’m going to calculate the absolute value of a number that you input. Would you like to input an int or a float? (Enter 1 for an int or 2 for a float.) 1 Please input the int. 5 The absolute value of 5 is 5. % absvalbytype I’m going to calculate the absolute value of a number that you input. Would you like to input an int or a float? (Enter 1 for an int or 2 for a float.) 1 Please input the int. -5 The absolute value of -5 is 5.

if Lesson 1 CS1313 Fall A More Complicated if Example Runs #3 % absvalbytype I’m going to calculate the absolute value of a number that you input. Would you like to input an int or a float? (Enter 1 for an int or 2 for a float.) 2 Please input the float. 5.5 The absolute value of is % absvalbytype I’m going to calculate the absolute value of a number that you input. Would you like to input an int or a float? (Enter 1 for an int or 2 for a float.) 2 Please input the float The absolute value of is

if Lesson 1 CS1313 Fall Compound Statement a.k.a. Block #1 A compound statement is a sequence of statements, with a well-defined beginning and a well-defined end, to be executed, in order, under certain circumstances. An if block is a compound statement. We’ll see others later. Although an if block is actually a sequence of statements, we can think of it as a single “super” statement in some contexts. Compound statements are also known as blocks. Thus, we speak of an if block.

if Lesson 1 CS1313 Fall Compound Statement a.k.a. Block #2 In C, a compound statement, also known as a block, is delimited by curly braces. That is, a compound statement (block): begins with a block open { ends with a block close }