freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

programminginansic-chapter5decisionmakingand(已修改)

2025-04-06 00:09 本頁面
 

【正文】 Chapter 5 Decision Making and Branching PROGRAMMING IN ANSI C 2 Question ? Questions: ? How do we judge whether a student pass an examination according to his score? ? How do we decide his grade according to his score? ? In human nature language: If…, then… ? In C: Decisionmaking statement (branch statement) 4/17/2023 3 Chapter 5 ? In this chapter, we will learn: ? Decisionmaking statement: if ? Conditional operator: ? : ? Multiway decisionmaking statement: switch ? Assisted control statement: break 4/17/2023 4 3 Forms of if Statement ? Form 1 – the most simple form if ( test expression ) statement。 test exp statement true (not 0) false (0) if ( score = 60 ) printf(He passed this examination!)。 4/17/2023 5 3 Forms of if Statement ? Form 2 – the most general form if ( test expression ) statement 1。 else statement 2。 if ( score = 60 ) printf(He passed this examination!)。 else printf(He failed in this examination!)。 test exp statement 1 true(not 0) false(0) statement 2 4/17/2023 6 3 Forms of if Statement ? Form 3 – the nested form if ( exp1 ) s1。 else if ( exp2 ) s2。 else …… else if ( expn ) sn。 else s。 exp1 s1 true false exp2 false expn false s2 …… sn s true true if ( score = 90 ) grade = 39。A39。 else if ( score = 80 ) grade = 39。B39。 else if ( score = 70 ) grade = 39。C39。 else if ( score = 60) grade = 39。D39。 else grade = 39。E39。 4/17/2023 7 if Statement ? The value of the test expression may be any type. If it equals zero, it is false, otherwise true. if ( a==b x==y ) printf ( a=b, x=y )。 if ( 3 ) printf ( OK )。 OK 4/17/2023 8 if ( a = 2 ) printf ( %d, a )。 else printf ( “ Wrong )。 = 0“if Statement ? The value of the test expression may be any type. If it equals zero, it is false, otherwise true. 2 Wrong 4/17/2023 9 if Statement ? The statement following if or else may be a single statement or a pound statement. main() { int x, y。 scanf( %d,%d, x, y )。 if ( x y ) x=y。 y=x。 else x++。 y++。 printf ( %d,%d\n, x, y)。 } Compile Error! Error … 6: Misplaced else in function main 4/17/2023 10 if Statement – Program 1 ? Input 2 real numbers, and output them in ascending order. ? Step1: Read 2 real numbers into variable x and y. ? Step2: If x is greater than y, exchange them. ? Step3: Output x and y. x y exchange x and y true false output x and y 4/17/2023 11 if Statement – Program 1 main() { float x, y, temp。 printf (Please input 2 numbers:\n)。 scanf ( %f %f, x, y )。 if ( x y ) { temp = x。 x = y。 y = temp。 } printf(The 2 numbers are: %, % \n, x, y)。 } Please input 2 numbers: ? The 2 numbers are: , 4/17/2023 12 if Statement – Program 1 ? Input 2 real numbers, and output them in ascending order. ? Step1: Read 2 real numbers into variable x and y. ? Step2: If x is less than y, output x and y, or else output y and x. x y output x and y true false output y and x 4/17/2023 13 if Statement – Program 1 main() { float x, y。 printf (Please input 2 numbers:\n)。 scanf ( %f %f, x, y)。 printf(The 2 numbers are: )。 if ( x y ) printf ( %, % \n, x, y )。 else printf ( %, % \n, y, x )。 } 4/17/2023 14 if Statement – Program 1 ? Programming Exercises : Input 3 real numbers, and output them in ascending order. (Homework!) 4/17/2023 15 if Statement – Program 2 ? Read in one year, and judge whether it is a leap year or not. ? Step1: Read in the year. ? Step2: If the test expression (year%4==0 year%100!=0)||(year%400==0) is true, then output it is a leap year, or else output it isn’ t a leap year. 4/17/2023 16 if Statement – Program 2 main() { int year。 printf (Please input the year:\n)。 scanf (%d, year)。 if ( (year%4==0year%100!=0)||(year%400==0) ) printf ( %d is a leap year!\n, year )。 else
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
公安備案圖鄂ICP備17016276號-1