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

正文內(nèi)容

第四章程序流程控制語句-文庫吧資料

2024-09-09 08:16本頁面
  

【正文】 / printf ( %4d, i++ )。 1 2 3 4 5 6 7 8 9 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 假設(shè) :行號為 i , 列號為 j i=6 j=5 i*j (1=i=9) (1=j=i) 則 :第 i 行中一共要輸出 i 個乘積 第 46 頁 167。 451 while語句 實例 ? 循環(huán)嵌套 在循環(huán)體中,又 包含 有 循環(huán) 語句,構(gòu)成 循環(huán)嵌套 。 == ++i。 變形 4: int i=0。 變形 3: int i=0。 while ( ++i = 100 ) == ++i。 == total+=i。 } printf(”Total=%d\n, total)。 while ( i = 100 ) { total = total + i。 451 while語句 實例 ? 例 3: 求 1到 100的之和。 } printf(chars=%d, lines=%d\n, nc, nl)。\n39。 while ( ( c = getchar( ) ) != EOF ) { ++ nc。 451 while語句 實例 ? 例 : 對輸入的行和字符進行計數(shù)。a39。) putchar( ch = getch( ) ); } 例 C3_5103 改寫: include main( ) { char ch。 while ( ch!=39。 39。a39。 451 while語句 實例 ? 例 : 從鍵盤中讀入一系列字符,直到輸入字母 a時才停止。 結(jié)論: 循環(huán)體中必須有能夠使循環(huán) 正常停止 的條件。 分析: 仍有問題,程序改變了 index,但方向錯了。 451 while語句 實例 ? 例 2: 分析下列程序段 index=1。 因為循環(huán)中 沒有 任何語句可以改變循環(huán)控制變量 index的初值 1。 while ( index 5 ) printf(”Good morning!\n”)。 例 C3_51011 { } 第 40 頁 167。 結(jié)論: while語句 循環(huán)體 中,一定要有能夠 對循環(huán)控制條件產(chǎn)生影響的語句 。 printf(”That\’s all this program does.\n”)。 while ( n3 ) printf (”n is %d\n”,n)。 } 例 C3_5101 第 39 頁 167。 total += num。 scanf (%d, amp。 /* total:存放累加和 */ while ( count10 ) /* 循環(huán)控制條件 */ { count ++。 /* count:計數(shù)器, num:輸入的整數(shù) */ count=0。 451 while語句 實例 ? 例 從鍵盤輸入 10個整數(shù),求這 10個整數(shù)的和。 451 while語句 ? while語句格式 while ( 表達式 ) 語句 ; 說明:語句 部分可以是 簡單語句 ,也可 以是復(fù)合語句 。 45 循環(huán)語句 ?循環(huán) 反復(fù)執(zhí)行同一段程序,直到滿足一定的條件后才停止執(zhí)行該段程序。 學(xué)生: 對!好象是這么回事 ...... 老師: 我們可以引出一個概念“ 循環(huán) ”,簡單而言: 循環(huán) 就是不斷 反復(fù)地執(zhí)行同一段程序。 45 循環(huán)語句 ? 提出問題 提問: 從鍵盤上輸入 10個整數(shù)并求和,怎么編程? 回答: 在程序中寫入 10個 scanf( )語句。 default: /* 輸入其它運算符 */ printf (Unknown operater.\n)。 else printf (%.2f/%.2f=%.2f\n, data1, data2, data1/data2)。break。break。break。data2)。data1, amp。 /* 定義操作數(shù)、操作符變量 */ printf(Enter your expression:)。 main ( ) { float data1, data2。 第 34 頁 167。 當(dāng) i=5 時: flag = 1; 調(diào)用 erorr(flag); 退出。 default: flag=2。 /* error 1 */ case 5: error(flag)。 /* no error */ break。 flag=1。 } 省略 case子句之后的語句 第 33 頁 167。 days=0。 /* 不是閏年 */ break。 year%100!=0 || year%400==0 ) days=29。 case 2: /* 處理 “ 平 ” 月 */ if ( year%4==0 amp。 case 4: case 6: case 9: case 11: /* 處理 “ 小 ” 月 */ days=30。 switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: /* 處理 “ 大 ” 月 */ days=31。year, amp。 442 選擇語句 switch語句 main( ) { int year, month, days。amp。 442 選擇語句 switch語句 ? 例 : 輸入 year年份和月 month, 求該月天數(shù)。 printf( Total = %.2f\n, total)。 default: rate=0。 case 8: rate=。 case 5: rate=。 case 3: rate=。 case 2: rate=。 /* 輸入本金和年限 */ switch ( year ) /*根據(jù)年限定利率 */ { case 1: rate=。money, amp。 /* 本金,月利率,本利合計 */ printf(Input money and year =?)。 include main( ) {int year。 442 選擇語句 switch語句 ? 例 : 計算存款本利。 可省略 break語句 ,但省略后會改變流程。 和 default 子句只能在 switch語句中使用,且 case和 default 只起標號作用 ,可出現(xiàn)在 switch中的任何位置。 同一個 switch中, case子句的 常量不能相同 ;在 嵌套 的switch語句中,不同層次的 switch之間,可有相同的常量。 442 選擇語句 switch語句 ? switch語句使用注意事項 if語句不同,僅能判斷一種關(guān)系:是否 恒等 。 } statement 5。 break。 break。 break。 …… default: 語句序列 n+1 } 執(zhí)行語句序列 1 =常量 1? 計算 表達式 的值 相等 不相等 break 執(zhí)行語句序列 2 =常量 2? 相等 不相等 break 執(zhí)行語句 序列 n+1 有 default? 有 沒有 第 28 頁 167。 442 選擇語句 switch語句 ? switch語句格式 switch (表達式 ) { case 常量 1: 語句序列 1 break。 轉(zhuǎn)換: printf (”You need %d %s of paint.”, cans , cans==1 ? ”can” : ”cans” )。 轉(zhuǎn)換: (cans==1)? printf(”You need 1 can of paint.”) : printf(”You need 2 cans of paint.”)。 ? 例: if ( cans==1 ) printf(”You need 1 can of paint.”)。 第 26 頁 167。 等價 等價 x = (y0) ? –y : y。 else x=y。 } 例 C3_4105 第 25 頁 167。 ) printf (\nIs a lower character.\n)。 c=39。 amp。 else if ( c=39。Z39。amp。A39。 ) printf (\nIs a digit character.\n)。 c=39。 amp。 else if ( c=39。 c=getch( )。 include main ( ) { char c。 441 選擇語句 if語句 ? 例 : 通過鍵盤輸入字符,將輸入的字符分為 控制 、 數(shù)字 、 大寫 字母、 小寫 字母和 其他 字符等五類。 printf( Total = %.2f\n, total)。 else rate=。 else if ( year == 5 ) rate=。 /* 根據(jù)年限定利率 */ else if ( year == 2 ) rate=。year)。 scanf(%f%d, amp。 float money,rate,total。 441 選擇語句 if語句 ? 采用 ifelse if結(jié)構(gòu)改寫。 printf( Total = %.2f\n, total)。 else rate=。 else if ( year == 5 ) rate=。 /* 根據(jù)年限定利率 */ else if ( year == 2 ) rate=。year)。 scanf(%f%d, amp。 float money,rate,total。銀行到期利息計算公式: 利息=本金月息利率 12存款年
點擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1