歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > PPT文檔下載  

C語言課件第4章-鍵盤輸入與屏幕輸出.ppt

  • 資源ID:16076618       資源大?。?span id="mkzooky" class="font-tahoma">1.44MB        全文頁數(shù):38頁
  • 資源格式: PPT        下載積分:9.9積分
快捷下載 游客一鍵下載
會員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要9.9積分
郵箱/手機:
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機號,方便查詢和重復(fù)下載(系統(tǒng)自動生成)
支付方式: 支付寶    微信支付   
驗證碼:   換一換

 
賬號:
密碼:
驗證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會被瀏覽器默認打開,此種情況可以點擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請知曉。

C語言課件第4章-鍵盤輸入與屏幕輸出.ppt

第4章 鍵盤輸入 和屏幕輸出,哈爾濱工業(yè)大學(xué) 計算機科學(xué)與技術(shù)學(xué)院 蘇小紅,本章學(xué)習(xí)內(nèi)容, 字符常量與轉(zhuǎn)義字符 字符輸出函數(shù)putchar() 字符輸入函數(shù)getchar() 數(shù)據(jù)的格式化輸出函數(shù)printf() 數(shù)據(jù)的格式化輸入函數(shù)scanf(),字符常量,字符常量是用單引號括起來的一個字符 a是字符常量,而a則是一個標(biāo)識符 3表示一個字符常量,而3則表示一個整數(shù) 轉(zhuǎn)義字符(Escape Character) 一些特殊字符(無法從鍵盤輸入或者另有他用)用轉(zhuǎn)義字符表示,字符型變量的取值范圍取決于計算機系統(tǒng)所使用的字符集 ASCII(美國標(biāo)準(zhǔn)信息交換碼)字符集 規(guī)定了每個字符所對應(yīng)的編碼 一個字符以其對應(yīng)的ASCII碼的二進制形式存儲在內(nèi)存中 一個字節(jié),保存一個字符(英文字母、數(shù)字、符號) 字符常數(shù)就是一個普通整數(shù),也可參與各種數(shù)學(xué)運算 每個字符具有一個0255之間的數(shù)值,可從ASCII表查出 注意:5和整數(shù)5的區(qū)別 5的ASCII碼值是53,字符常量,4.1單個字符的輸入輸出,通過調(diào)用標(biāo)準(zhǔn)庫函數(shù)來實現(xiàn) #include 字符輸出函數(shù) putchar(ch) 輸出一個字符ch 字符輸入函數(shù) getchar() 無參數(shù) 函數(shù)值為從輸入設(shè)備接收的字符,【例4.1】大小寫英文字母轉(zhuǎn)換,Press a key and then press Enter: B b,4.2數(shù)據(jù)的格式化屏幕輸出,格式 printf(格式控制字符串, 輸出項表列); printf(a=%d b=%f, a, b); 可以輸出若干任意類型的數(shù)據(jù),函數(shù)名,可選輸 出表列,普通字符,%c character以字符形式輸出單個字符 %s string 輸出一個字符串 %d decimal 以帶符號十進制整數(shù)輸出 %f float 以小數(shù)形式輸出浮點數(shù)(6位小數(shù)) %e exponent 以標(biāo)準(zhǔn)指數(shù)形式輸出(6位小數(shù)) %g 選用%f,%e中輸出寬度較小的一種格式 %o octal 以八進制無符號整數(shù)輸出(無前導(dǎo)0) %x hex 以十六進制無符號整數(shù)輸出(無前導(dǎo)0 x) %u unsigned 以十進制無符號整數(shù)輸出,printf()格式字符,【例4.2】大小寫英文字母轉(zhuǎn)換,Press a key and then press Enter: B b, 98,m 表示數(shù)據(jù)占用的最小寬度 數(shù)據(jù)寬度大于m,按實際寬度輸出 數(shù)據(jù)寬度小于m時,補空格 n 對實數(shù)表示輸出n位小數(shù) 對字符串表示最多輸出的字符個數(shù) l 長整型整數(shù),加在d、o、x、u前 L long double型數(shù),加在f、e、g前 - 改變輸出內(nèi)容的對齊方式 默認為右對齊,printf()的格式修飾符,printf()的格式修飾符,Format for float: %f General format: % . f,Example: printf(Value is:%10.4f, 32.6784728);,Value is: 32.6785,printf()的格式修飾符,Example: printf(Value is:%10f, 32.6784728);,Value is: 32.678473,Example: printf(Value is:%.3f, 32.6784728);,Value is:32.678,printf()的格式修飾符,Input r: 5.3 printf WITHOUT width or precision specifications: circumference = 33.300854, area = 88.247263 printf WITH width and precision specifications: circumference = 33.30, area = 88.25,【例4.3】計算圓的周長和面積,4.3數(shù)據(jù)的格式化鍵盤輸入,格式 scanf(格式控制字符串, 地址表列); scanf(%d,%f, ,c 以字符形式輸入單個字符 s 輸入字符串,以非空字符開始,遇第一個 空白字符結(jié)束 d 以帶符號十進制形式輸入整型數(shù)據(jù) f 以小數(shù)形式輸入浮點數(shù) e 以標(biāo)準(zhǔn)指數(shù)形式輸入 o 以八進制無符號形式輸入(無前導(dǎo)0) x 以十六進制無符號形式輸入(無前導(dǎo)0 x),scanf()的格式字符,m 表示數(shù)據(jù)占用的寬度 l 加在d、o、x、u前:輸入長整型 加在f、e 前:輸入雙精度型 L 加在f、e 前:輸入long double型 h 加在d、o、x 前:輸入短整型 * 本輸入項在讀入后不賦給相應(yīng)的變量,scanf ()的格式修飾符,#include main() int a, b; printf(Please input a and b:); scanf(%2d%*2d%2d, ,Please input a and b:,a=12, b=56, a+b = 68,123456,跳過一個輸入項,輸入數(shù)據(jù)的格式控制,#include main() int a, b; scanf(%d %d, ,問題1:當(dāng)要求程序輸出結(jié)果為 a = 12, b = 34 時,用戶應(yīng)該如何輸入數(shù)據(jù)?,12 34,輸入數(shù)據(jù)的格式控制例4.4,#include main() int a, b; scanf(%d %d, ,問題2:當(dāng)限定用戶輸入數(shù)據(jù)以逗號為分隔符,即輸入數(shù)據(jù)格式為: 12,34 時,應(yīng)修改程序中的哪條語句?怎樣修改?,輸入數(shù)據(jù)的格式控制例4.4,#include main() int a, b; scanf(%d %d, ,問題3:語句scanf(%d %d, 時,用戶應(yīng)該如何輸入數(shù)據(jù)?,a = 12, b = 34,輸入數(shù)據(jù)的格式控制例4.4,#include main() int a, b; scanf(%d %d, ,問題4:限定用戶輸入數(shù)據(jù)為以下格式 1234 同時要求程序輸出結(jié)果為a = 12, b = 34,%2d%2d,輸入數(shù)據(jù)的格式控制例4.4,#include main() int a, b; scanf(%d %d, ,問題5:限定用戶輸入數(shù)據(jù)為以下格式 12 34 同時要求程序輸出結(jié)果為a = 12 ,b = 34,%d ,b = %d,輸入數(shù)據(jù)的格式控制例4.4,#include main() int a, b; scanf(%d %d, ,問題6:設(shè)計程序使得用戶可以以任意字符(回車、空格、制表符、逗號、其他)作為分隔符進行數(shù)據(jù)的輸入,輸入數(shù)據(jù)的格式控制例4.4,#include main() int a, b; scanf(%d %d, ,問題7:輸入123456時程序的輸出結(jié)果是什么?,輸入數(shù)據(jù)的格式控制例4.4,a = 12, b = 56,#include main() int a, b; scanf(%d %d, ,問題8:如果用戶輸入了非法字符,例如輸入了12 3a,那么程序運行結(jié)果如何?,輸入數(shù)據(jù)的格式控制例4.4,12 3a a = 12, b = 3,#include main() int a, b; scanf(%d %d, ,問題9:如果用戶輸入的是123a,那么結(jié)果又會如何呢?,輸入數(shù)據(jù)的格式控制例4.4,123a a = 123, b = -858993460,#include main() int a, b; scanf(%d %d, ,問題10:如果程序第5行語句修改為.,那么結(jié)果又會如何呢?,輸入數(shù)據(jù)的格式控制例4.4,#include main() int data1, data2, sum; char op; printf(Please enter the expression data1 + data2n); scanf(%d%c%d, ,Please enter the expression data1 + data2,第1次測試,12 + 3,12 4199288 = 4199300,C格式符的問題及解決例4.5,#include main() int data1, data2, sum; char op; printf(Please enter the expression data1 + data2n); scanf(%d%c%d, ,Please enter the expression data1 + data2,第2次測試,12 3,12 3 = 15,C格式符的問題及解決例4.5,#include main() int data1, data2, sum; char op; printf(Please enter the expression data1 + data2n); scanf(%d%c%d, ,Please enter the expression data1 + data2,第3次測試,12+3,12+3 = 15,C格式符的問題及解決例4.5,#include main() int a; char b; float c; printf(Please input an integer:); scanf(%d, ,Please input an integer:,希望得到的運行結(jié)果,12,Please input an character :,a,Please input a float number:,3.5,integer:12,character :a,float number:3.500000,C格式符的問題及解決例4.6,#include main() int a; char b; float c; printf(Please input an integer:); scanf(%d, ,Please input an integer:,結(jié)果好像很奇怪呀!,12,Please input an character :,a,Please input a float number:,3.5,integer:12,float number:3.500000,C格式符的問題及解決例4.6,#include main() int a; char b; float c; printf(Please input an integer:); scanf(%d, ,Please input an integer:,程序修改后得到的運行結(jié)果,12,Please input an character :,a,Please input a float number:,3.5,integer:12,character :a,float number:3.500000,C格式符的問題及解決例4.6,#include main() int a; char b; float c; printf(Please input an integer:); scanf(%d, ,C格式符的問題及解決例4.6,#include main() int data1, data2, sum; char op; printf(Please enter the expression data1 + data2n); scanf(%d %c%d, ,12+3,12 + 3,12 + 3,再回頭來看例4.5 如何以任意分隔符輸入加法算式?,格式輸入函數(shù)常見錯誤,scanf(%d,%fn, 幾點忠告 不要拘泥于細節(jié) 不要死記硬背 在使用中慢慢掌握,注意!,Questions and answers,

注意事項

本文(C語言課件第4章-鍵盤輸入與屏幕輸出.ppt)為本站會員(za****8)主動上傳,裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因為網(wǎng)速或其他原因下載失敗請重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!