【文章內(nèi)容簡介】
and ifelse Statements printf(“you 掛了” )。 The single statement can Either be put into a bracket Or used with indentation. 29 Exp: include int main () { int score。 printf(Please input your score:)。 scanf(%d,amp。score)。 if (score=60) { printf(Passed!\n)。 } else { printf(Sorry you failed!\n)。 } return 0。 } 30 The ifelse Chain ? Nested if statement: if (expression1) statement1。 else if (expression2) statement2。 else statement3。 31 sgn( x ) 32 sgn( x ).2 33 The if/else Selection Structure ? If student’s grade is greater than or equal to 90 Print “A” else If student’s grade is greater than or equal to 80 Print “B” else If student’s grade is greater than or equal to 70 Print “C” else If student’s grade is greater than or equal to 60 Print “D” else Print “F” 34 if .. else if chain else if if exp1 exp3 exp2 else if 1 1 1 0 case1 case2 case3 case4 35 The switch Statement Terminated with a colon default is optional If the break statement was omitted, the following case would be executed 36 switch (exp) case v1: case v2: statements statements statements statements statements case v3: case v4: case v5: default: 37 Case study: binary decoder 38 Data Validation ? Defensive programming is a