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

正文內(nèi)容

[理學(xué)]第05章結(jié)構(gòu)體與共用體-資料下載頁

2025-01-19 14:55本頁面
  

【正文】 n, tue, wed, thu, fri, sat} today, nextday。 today = sun。 nextday = mon。 if (today == sat) nextday = sun。 today = 100。 √ C編譯對枚舉元素實(shí)際上按 整型常量 處理,當(dāng)遇到枚舉元素列表時(shí),編譯程序就把其中 第一個(gè)標(biāo)識(shí)符賦 0值,第二、三、 … 個(gè)標(biāo)識(shí)符依此賦 1,2,… 。 enum weekday {sun, mon, tue, wed, thu, fri, sat} today, nextday。 0 1 2 3 4 5 6 today = sun。 printf(today = %d, today)。 運(yùn)行結(jié)果: today = 0 廈門理工學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)系 29 if (today == 6) nextday = 0。 if (today == sat) nextday = sun。 可以在枚舉類型定義時(shí)指定枚舉元素的值 enum weekday {sun, mon = 5, tue, wed=10, thu, fri, sat}。 0 5 6 10 11 12 13 注意: 枚舉元素是常量,在程序中不可對它賦值。 例如: sun = 0。 mon = 1。將產(chǎn)生錯(cuò)誤。 定義枚舉類型的好處: ? 用標(biāo)識(shí)符表示數(shù)值 ,增加了程序的可讀性 清晰 不清晰 ? 可限制變量的取值范圍 如 today只能取 sun~ sat中的值 廈門理工學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)系 30 例題 510 枚舉元素序號 Void main() { enum weekday {sun, mon, tue, wed, thu, fri, sat} a,b,c。 a=sun。 b=mon。 c=tue。 printf(“%d,%d,%d”,a,b,c)。 } 思考:運(yùn)行結(jié)果? 廈門理工學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)系 31 5 .8 程序設(shè)計(jì)舉例 例 511 已知某年的元旦是星期幾,打印該年某一月份的日歷表 include typedef struct { int year,mon,day。 enum weekday {nun,mon,tue,wed,thu,fri,sat}week。 }daily。 void main( ) { daily days。 printf(Which year?)。 scanf(%d,amp。)。 /* 哪年日歷 */ printf(year %4d,Month 1,day 1 is weekday?\n,)。 printf(Sun, 1Mon, 2Tue, 3Wed, 4Thu, 5Fri, 6Sat:)。 scanf(%d,amp。)。 = = 1。 montable(days)。 } 31 廈門理工學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)系 32 montable(daily d) { int i, s, ds,t。 daily md。 = 。 = 1。 printf(Which month?)。 scanf(%d,amp。)。 /* 查看當(dāng)年哪月日歷表 */ t=(%4==0 amp。amp。 %100!=0 || %400==0)?29:28。 for(s=0, i=1。i=。 i++) { switch(i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: ds=31。 break。 case 2: ds=t。break。 case 4: case 6: case 9: case 11: ds = 30。 } s += ds。 } s =ds。 32 廈門理工學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)系 33 = (s + )%7。 /* 計(jì)算該月 1號是星期幾 ,同時(shí)計(jì)算該月天數(shù)存入 ds中 */ printf(\t===%4d Year, %2d Month ==\n,)。 printf(....................................\n)。 printf(%5s%5s%5s%5s%5s%5s%5s\n, Sun,Mon,Tue, Wed,Thu,Fri,Sat)。 printf(....................................\n)。 for(i = 0。 i * 5。 i++) printf( )。 /* 計(jì)算該月 1號的打印位置 */ for(i = 1。 i=ds。 i++) { printf(%5d,i)。 if(++ == 7) { = 0。 printf(\n)。} /* 超過一周換行打印 */ } if( != 0) printf(\n)。 printf(....................................\n)。 } 33 廈門理工學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)系 34 總結(jié) 結(jié)構(gòu)體是由若干數(shù)據(jù)項(xiàng)組合而成的復(fù)雜數(shù)據(jù)對象,這些數(shù)據(jù)項(xiàng)稱為結(jié)構(gòu)體的成員。 定義一個(gè)結(jié)構(gòu)體,需要給出各個(gè)成員的類型及名稱。 結(jié)構(gòu)體定義僅描述了一個(gè)結(jié)構(gòu)體的形式。要在程序里使用結(jié)構(gòu)體,需要聲明結(jié)構(gòu)體變量。 訪問結(jié)構(gòu)體成員的操作要用圓點(diǎn)運(yùn)算符( .),一般形式為:結(jié)構(gòu)體變量名 .成員名。
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1