




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、1、把一個(gè)學(xué)生的信息(包括學(xué)號(hào)、姓名、性別、住址)放在一個(gè)結(jié)構(gòu)體變量中,然后輸出這個(gè)學(xué)生的信息。#include int main()struct student long int num; char name20;char sex; char addr20;a=10101,“ li lin” , m , “ 123 beijing road” ; printf(no.:%ldnname:%sn sex:%cnaddress:%sn,a.num,,a.sex,a.addr);return 0; 2、輸入兩個(gè)學(xué)生的學(xué)號(hào)、姓名和成績,輸出成績較高學(xué)生的學(xué)號(hào)、姓名和成績#include
2、int main() struct student int num;char name20;float score;student1,student2; scanf(%d%s%f,&student1.num,, &student1.score); scanf( “ %d%s%f ” ,&student2.num,, &student2.score); printf(the higher score is:n);if (student1.scorestudent2.score)printf(%d %s %6.2f
3、n,student1.num,, student1.score);else if (student1.scorestudent2.score)printf(%d %s %6.2fn,student2.num,, student2.score);elseprintf(%d %s %6.2fn,student1.num,, student1.score);printf(%d %s %6.2fn,student2.num,, student2.score);return 0;3、有 3 個(gè)候選人,
4、每個(gè)選民只能投票選一人,要求編一個(gè)統(tǒng)計(jì)選票的程序,先后輸入被選人的名字,最后輸出各人得票結(jié)果。#include #include struct person char name20; int count; leader3=“ li ” ,0, “ zhang” ,0, “ sun” ,0;int main() int i,j; char leader_name20; for (i=1;i=10;i+) scanf(“ %s ” ,leader_name); for(j=0;j3;j+)if(strcmp(leader_name,)=0) leaderj.count+;f
5、or(i=0;i3;i+)n“ ,,leaderi.count);return 0;4、有 n 個(gè)學(xué)生的信息(包括學(xué)號(hào)、姓名、成績),要求按照成績的高低順序輸出各學(xué)生的信息。#include struct student int num; char name20; float score; ; int main() struct student stu5=10101,zhang,78,10103,wang,98.5,10106,li, 86 ,10108, “ ling ” , 73.5,10110, “ fun” , 100 ; struct student temp
6、; const int n = 5 ; int i,j,k;printf(the order is:n);for(i=0;in-1;i+) k=i;for(j=i+1;jstuk.score) k=j;temp=stuk;stuk=stui; stui=temp; for(i=0;in;i+)printf(%6d %8s %6.2fn,stui.num,,stui.score);printf(n);return 0;5、通過指向結(jié)構(gòu)體變量的指針變量輸出結(jié)構(gòu)體變量中成員的信息。#include #include int main() struct student long nu
7、m;char name20;char sex;float score;struct student stu_1; struct student * p; p=&stu_1; stu_1.num=10101; strcpy(stu_1.name,“ li lin” );stu_1.sex=m ; stu_1.score=89.5;n”,p-.num);printf(name:%sn, );n”, p-.sex);printf(” score:%5.1fn” ,stu_1.score); return 0;6、有 3 個(gè)學(xué)生的信息,放在結(jié)構(gòu)體數(shù)組中,要求輸出全部學(xué)生的信息。#
8、include struct student int num; char name20;char sex; int age; ;struct student stu3=10101,li lin,m,18,10102,zhang fun,m,19,10104,wang min,f,20 ;int main() struct student *p; printf( no. name sex agen);for(p=stu;pnum, p-name, p-sex, p-age); return 0;7、有 n 個(gè)結(jié)構(gòu)體變量,內(nèi)含學(xué)生學(xué)號(hào)、姓名和3 門課程的成績。要求輸出平均成績最高的學(xué)生的信息 (包
9、括學(xué)號(hào)、姓名、3 門課程成績和平均成績)。#include #define n 3 struct student int num; char name20; float score3; float aver; ; int main() void input(struct student stu); struct student max(struct student stu); void print(struct student stu); struct student stun; input(stu); print(max(stu); return 0; void input(struct s
10、tudent stu) int i; printf( 請(qǐng)輸入各學(xué)生的信息:學(xué)號(hào)、姓名、三門課成績:n); for(i=0;in;i+) scanf(%d %s %f %f %f,&stui.num,,&stui.score0,&stui.score1,&stui.score2); stui.aver=(stui.score0+stui.score1+stui.score2)/3.0; struct student max(struct student stu) int i,m=0; for(i=0;istum.aver) m=i; return
11、 stum; void print(struct student stud) printf(n成績最高的學(xué)生是:n); printf(學(xué)號(hào):%dn姓名:%sn三門課成績:%5.1f,%5.1f,%5.1fn平均成績:%6.2fn,stud.num,,stud.score0,stud.score1,stud.score2,stud.aver); 8、有若干個(gè)人員的數(shù)據(jù),其中有學(xué)生和教師。學(xué)生的數(shù)據(jù)中包括:姓名、號(hào)碼、性別、職業(yè)、班級(jí)。教師的數(shù)據(jù)包括:姓名、號(hào)碼、性別、職業(yè)、職務(wù)。要求用同一個(gè)表格來處理。#include union categ int clas; char po
12、sition10; ; struct int num; char name10; char sex; char job; union categ category person2; int main() int i; for(i=0;i2;i+) scanf(%d %s %c %c“ ,&personi.num, &, &personi.sex,&personi.job); if(personi.job = s) scanf(%d“ ,&personi.category.clas);else if(personi.job = t)
13、scanf(“ %s” ,personi.category.position); else printf(“ input error!” ); printf(n); for(i=0;i2;i+) if (personi.job = s ) printf(%-6d%-10s%-4c%-4c% -10dn,personi.num,personi. name,personi.sex,personi.job, personi.category.clas); else printf(%-6d%-10s%-4c%-4c% -10sn,personi.num,personi. name,personi.se
14、x, personi.job, personi.category.position); return 0; 9、編程,輸入2 個(gè)時(shí)刻 , 定義一個(gè)時(shí)間結(jié)構(gòu)體類型(包括時(shí)分秒),計(jì)算 2 個(gè)時(shí)刻之間的時(shí)間差。#include typedef struct mytime int hour; int min; int sec; t; int main() t t1, t2, t3; int sec1, sec2, sec3; printf( 輸入兩個(gè)時(shí)間值,以xx:xx:xx的格式 n); scanf(%d:%d:%d, t1.hour, t1.min, t1.sec); scanf(%d:%d:%
15、d, t2.hour, t2.min, t2.sec); sec1 = t1.hour * 3600 + t1.min * 60 + t1.sec; sec2 = t2.hour * 3600 + t2.min * 60 + t2.sec; if( sec1 = sec2 ) sec3 = sec1 - sec2; else sec3 = sec2 - sec1; t3.hour = sec3 / 3600; sec3 %= 3600; t3.min = sec3 /60; t3.sec = sec3 %60; printf( 時(shí)間差是 %d 小時(shí) %d 分%d 秒n, t3.hour, t3.m
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 腹股溝疝的臨床表現(xiàn)及護(hù)理
- 創(chuàng)新創(chuàng)業(yè)載夢前行
- 2024學(xué)年濟(jì)南市高新區(qū)八年級(jí)語文第一學(xué)期期末測試卷附答案解析
- 2025年大學(xué)輔導(dǎo)員招聘考試:學(xué)生社團(tuán)管理案例分析真題解析匯編
- 2025年中學(xué)教師資格考試《綜合素質(zhì)》學(xué)生心理輔導(dǎo)案例實(shí)戰(zhàn)演練試卷
- 獸醫(yī)養(yǎng)殖行業(yè)安全知識(shí)培訓(xùn)
- 2025年專升本藝術(shù)概論模擬試卷-藝術(shù)鑒賞與審美心理培養(yǎng)
- 2025年錫基合金焊粉合作協(xié)議書
- 節(jié)后復(fù)工安全教育培訓(xùn)
- 腓骨骨折治療方案
- 2025年勞動(dòng)實(shí)踐課面試題及答案
- 雪佛蘭創(chuàng)酷說明書
- 光華學(xué)校年級(jí)校園足球聯(lián)賽秩序冊(cè)
- MSDS-丙烯酸乳液(水性復(fù)膜膠水)
- 消防安全自查表
- 常見急危重癥院前急救流程(匯總)
- 單片機(jī)英文參考文獻(xiàn)
- 生態(tài)溝渠施工方案
- 04設(shè)備設(shè)施安全檢查表
- 部編(統(tǒng)編)版 一年級(jí)下冊(cè)語文 教材解讀分析與教學(xué)建議 講座課件(62頁精品PPT)
- 安全責(zé)任承諾書范本
評(píng)論
0/150
提交評(píng)論