版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選ppt第七章第七章 預(yù)處理命令預(yù)處理命令第九章第九章 結(jié)構(gòu)體與共用體結(jié)構(gòu)體與共用體精選ppt#include #define MYS) z=x;x=y;y=z;void main()float a=5,b=16,c;MYS);printf(%f %f %fn,a,b,c);7.1.宏調(diào)用實(shí)現(xiàn)變量a、b內(nèi)容的交換。精選ppt7.2.程序輸出結(jié)果(36)。#include #define f(x) x*xvoid main()int a=6,b=2,c;c=f(a)/f(b); /a*a/b*bprintf(%dn,c);精選ppt7.3.程序輸出結(jié)果(9.840000)。#include #
2、define PR(a) printf(“%f,a)#define F(y) 3.84+y#define PRINT(a) PR(a); putchar(n)void main()int x=2;PRINT(F(3)*x);精選ppt7.4.s)實(shí)現(xiàn)兩個(gè)參數(shù)互換。#include #define s) a=ab; b=ba;a=ab;/異或,對a和b類型有限制/#define s) a=a+b;b=a-b;a=a-b;/求和,對a和b上界有限制void main()int a, b;scanf(%d%d,&a,&b);s);printf(%d %dn,a,b);精選ppt#in
3、clude #define MyLpha(c) (c=97)?1:0void main()char c;scanf(%c,&c);if (MyLpha(c)printf(%cn,c-32);elseprintf(%cn,c+32);7.5.編寫宏定義MyLpha(c),以判定c是大寫字母還是小寫字母,當(dāng)c是小寫字母時(shí)宏調(diào)用取值為1,當(dāng)c是大寫字母時(shí)宏調(diào)用取值為0。 精選ppt9.1a. 定義一個(gè)圖書館相關(guān)信息的結(jié)構(gòu)體類型和結(jié)構(gòu)體變量,其中包括成員書號、書名、作者、出版社和價(jià)格;從鍵盤輸入10本圖書信息,計(jì)算并輸出這10本圖書的平均價(jià)格。#include #include #define
4、 N 10 typedef struct Bookcardchar num10;char name30;char author30;char publisher60;float price; Bookcard;void main()Bookcard bookN;int i=0;float meanprice=0;for (i=0;iN;i+)scanf(%s,booki.num);scanf(%s,);scanf(%s,booki.author);scanf(%s,booki.publisher);scanf(%f,&booki.price);meanprice=m
5、eanprice+booki.price;meanprice=meanprice/N;printf(%.2f,meanprice);精選ppt9.1b.#include #include #define N 10typedef struct Bookcardchar num10;char name30;char author30;char publisher60;float price; Bookcard;void main() /用指針實(shí)現(xiàn)賦值Bookcard bookN, *b;float meanprice=0;for (b=book;bnum);gets(b-name);gets(b-
6、author);gets(b-publisher);scanf(%f,&b-price);meanprice=meanprice+b-price;getchar();/fflush(stdin);meanprice=meanprice/N;printf(%.2f,meanprice);精選ppt9.2a. 在第1題定義的結(jié)構(gòu)體類型中增加一個(gè)成員出版日期,該日期是一個(gè)嵌套的結(jié)構(gòu)類型變量,其中包括年、月、日;設(shè)計(jì)一個(gè)輸入/輸出圖書館信息的函數(shù)read和print;并編寫主函數(shù)定義一個(gè)10個(gè)元素的結(jié)構(gòu)數(shù)組,分別調(diào)用輸入/輸出函數(shù)輸入和輸出圖書信息。#include #include #def
7、ine N 10typedef struct Dateint year;int month;int day;Date;typedef struct Bookcardchar num10;char name30;char author30;char publisher60;float price;Date date; Bookcard;void read(Bookcard *p)Bookcard *b;for (b=p;bnum);gets(b-name);gets(b-author);gets(b-publisher);scanf(%f,&b-price);scanf(%d%d%d,&
8、amp;b-date.year,&b-date.month,&b-date.day); getchar();/fflush(stdin);精選ppt9.2b.void print(Bookcard *p)Bookcard *b;for (b=p;bnum);puts(b-name);puts(b-author);puts(b-publisher);printf(%.2fn,b-price);printf(%d %d %dn,b-date.year,b-date.month,b-date.day);void main()Bookcard bookN;read(book);prin
9、t(book);精選ppt9.3a. 在第2題的基礎(chǔ)上,增加一個(gè)按書號遞增排序的排序函數(shù)sort,在主函數(shù)中調(diào)用排序函數(shù)再輸出圖書信息。void exchange(Bookcard *b, Bookcard *d)Bookcard book1;strcpy(book1.num,b-num);strcpy(,b-name);strcpy(book1.author,b-author);strcpy(book1.publisher,b-publisher);book1.price=b-price;book1.date.year=b-date.year;book1.date.mon
10、th=b-date.month;book1.date.day=b-date.day;strcpy(b-num,d-num);strcpy(b-name,d-name);strcpy(b-author,d-author);strcpy(b-publisher,d-publisher);b-price=d-price;b-date.year=d-date.year;b-date.month=d-date.month;b-date.day=d-date.day;strcpy(d-num,book1.num);strcpy(d-name,);strcpy(d-author,book
11、1.author);strcpy(d-publisher,book1.publisher);d-price=book1.price;d-date.year=book1.date.year;d-date.month=book1.date.month;d-date.day=book1.date.day;book1=*b;*b=*d;*d=book1;精選ppt9.3b.void sort(Bookcard *p)Bookcard *b, *d;for (b=p;bp+N-1;b+)for(d=b+1;dnum,d-num)0exchange(b,d);void main()Bookcard boo
12、kN;read(book);sort(book);print(book);B0pbdB1B2B3精選ppt9.4a. 建立一個(gè)鏈表,每個(gè)節(jié)點(diǎn)包括:書號、書名、作者和出版社,并編寫按書號查詢和刪除節(jié)點(diǎn)的函數(shù)。#include #include #include typedef struct Bookcardchar num10;char name30;char author30;char publisher60;Bookcard *next; Bookcard;Bookcard *create()Bookcard *head;Bookcard *p, *r;char num10;head=NUL
13、L;gets(num);while(strlen(num)!=0)printf(%dn,strlen(num);p=(Bookcard*)malloc(sizeof(Bookcard);strcpy(p-num,num);gets(p-name);gets(p-author);gets(p-publisher);if (head=NULL) head=p;elser-next=p;r=p;gets(num);if (r!=NULL)r-next=NULL;printf(endn);return head;B0headrB1B2B3p精選ppt9.4b.void print(Bookcard *
14、p)Bookcard *b;b=p;while(b!=NULL)puts(b-num);puts(b-name);puts(b-author);puts(b-publisher);b=b-next;void search(Bookcard *p)Bookcard *b;char num10;gets(num);b=p;while(b!=NULL)if (strcmp(num,b-num)=0) puts(b-num);puts(b-name);puts(b-author);puts(b-publisher);b=b-next;精選ppt9.4c. Bookcard *delet(Bookcar
15、d *p)Bookcard *b ,*pb;char num10;gets(num);pb=p; b=p;while(b!=NULL)if (strcmp(num,b-num)=0)if (b=p)p=b-next;elsepb-next=b-next;return p;pb=b;b=b-next;void main()Bookcard *head;head=create();print(head);search(head);head=delet(head);print(head);B0ppbbB1B2B3精選ppt9.5a. 根據(jù)以下學(xué)生情況表,編制一個(gè)C語言程序,分別應(yīng)用選擇法和冒泡法對該
16、學(xué)生情況表按成績從低到高進(jìn)行排序處理并輸出。 #include #include #define N 5typedef struct Studentchar num10;char name10;char sex;int age;float grade; Student;void read(Student *p)Student *b;for (b=p;bnum);gets(b-name);scanf(%c%d%f,&b-sex,&b-age,&b-grade);getchar();/fflush(stdin);精選ppt9.5b. void print(Student *
17、p)int i=0;for (i=0;inum);puts(pi-name);printf(%c %d %fn,pi-sex,pi-age,pi-grade);精選ppt9.5c. void sort(Student *p)Student *q;int i=0,j=0;for(i=0;iN-1;i+)for(j=i+1;jgradegrade)q=pi;pi=pj;pj=q;void main()Student stuN, *sN;int i;for (i=0; iN; i+)si=&stui;read(stu);sort(s);print(s);精選ppt9.6. 已知每個(gè)學(xué)生情況的
18、結(jié)點(diǎn)結(jié)構(gòu)類型。(1)初始鏈表為空(2)新結(jié)點(diǎn)插入表頭(3)輸出鏈表(4)刪除結(jié)點(diǎn)并輸出 #include #include #include typedef struct Studentchar num10;char name10;char sex;int age;float grade;Student *next; Student;Student *create()Student *head;Student *p;char num10;head=NULL;gets(num);while(strlen(num)!=0)p=(Student*)malloc(sizeof(Student);str
19、cpy(p-num,num);gets(p-name);scanf(%c%d%f,&p-sex,&p-age,&p-grade);getchar();p-next=head;head=p;gets(num);printf(endn);return head;S1headS0S2p精選ppt9.6b.void print(Student *p)Student *b;b=p;while(b!=NULL)puts(b-num);puts(b-name);printf(%c %d %.2fn,b-sex,b-age,b-grade);b=b-next;B0ppbbB1B2B3S
20、tudent *delet(Student *p)Student *b ,*pb;int age;scanf(%d,&age);pb =p; b=p;while(b!=NULL)if (age=b-age)if (b=p)p=b-next;elsepb -next=b-next;return p;pb=b;b=b-next;精選ppt9.6c.void main()Student *head;head=create();head=delet(head);print(head);精選ppt9.7. 13個(gè)人圍成一圈,從第1個(gè)人開始順序報(bào)號1、2、3。凡報(bào)到“3”者退出圈子。編程找到最后留
21、在圈子的人原來的序號。 #include #define N 13struct personint number;int nextp;linkN+1;void main()int i,count,h;for (i=1;i=N;i+)if (i=N)linki.nextp=1;elselinki.nextp=i+1;linki.number=i;count=0;h=N;while(countN-1)i=0;while(i!=3)h=linkh.nextp;if(linkh.number)i+;linkh.number=0;count+;for (i=1;i=N;i+)if (linki.numb
22、er)printf(%3d,linki.number);printf(n);精選ppt9.8a. 兩個(gè)鏈表La和Lb合并成一個(gè)遞增有序的單鏈表Lc。#include #include #include typedef struct Bookcardchar num10;char publisher60;Bookcard *next; Bookcard;Bookcard *create()Bookcard *head;Bookcard *p, *r;char num10;head=NULL;gets(num);while(strlen(num)!=0)p=(Bookcard*)malloc(si
23、zeof(Bookcard);strcpy(p-num,num);gets(p-publisher);if (head=NULL)head=p;elser-next=p;r=p;gets(num);if (r!=NULL)r-next=NULL;printf(endn);return head;精選ppt9.8b.Bookcard *combin(Bookcard *La, Bookcard *Lb)/把Lb的結(jié)點(diǎn)都插入到La中Bookcard *pa1, *pa2, *pb1, *pb2;pa1=pa2=La;pb1=pb2=Lb;dowhile(strcmp(pb1-num,pa1-num
24、)0)&(pa1-next!=NULL)pa2=pa1;pa1=pa1-next;/在La中找比pb1小的結(jié)點(diǎn),pa2指向if(strcmp(pb1-num,pa1-num)next=pb1;pb1=pb1-next;pb2-next=pa1;pa2=pb2;pb2=pb1;else if (pa1-next=NULL)break;while(pb1!=NULL);if(pb1!=NULL)&(strcmp(pb1-num,pa1-num)0)&(pa1-next=NULL)pa1-next=pb1;return La;精選pptA0LaA1A2A3LbB2pa2pa1
25、pb1B1B0pb2A0LaA1A2A3B0LbB1B2pa2pa1pb1pb2精選ppt9.8c.void main()Bookcard *La, *Lb, *Lc;La=create();Lb=create();Lc=combin(La,Lb);print(Lc);精選ppt9.9a. 單鏈表結(jié)構(gòu)實(shí)現(xiàn)直接選擇排序。void print(Bookcard *p)Bookcard *b;b=p;while(b!=NULL)puts(b-num);puts(b-publisher);b=b-next;Student *create()Student *head, *p;char num10;he
26、ad=NULL;gets(num);while(strlen(num)!=0)p=(Student*)malloc(sizeof(Student);strcpy(p-num,num);gets(p-name);scanf(%c%d%f,&p-sex,&p-age,&p-grade);getchar();p-next=head;head=p;gets(num);printf(endn);return head;精選ppt9.9b. 單鏈表結(jié)構(gòu)實(shí)現(xiàn)直接選擇排序。Student *sort(Student *p)Student *head;Student *pnow, *pnow2, *pmin, *p1, *p2;head=p;pnow=head;/當(dāng)前結(jié)點(diǎn)pnow2=head;/pnow先繼w
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 酒店康樂部培訓(xùn)管理制度
- 試用期員工培訓(xùn)管理制度
- 培訓(xùn)機(jī)構(gòu)檔案制度
- 未來五年長鰭鱈魚企業(yè)數(shù)字化轉(zhuǎn)型與智慧升級戰(zhàn)略分析研究報(bào)告
- 未來五年跨學(xué)科研究服務(wù)企業(yè)數(shù)字化轉(zhuǎn)型與智慧升級戰(zhàn)略分析研究報(bào)告
- 未來五年新形勢下提供房車場地行業(yè)順勢崛起戰(zhàn)略制定與實(shí)施分析研究報(bào)告
- 未來五年水產(chǎn)品企業(yè)ESG實(shí)踐與創(chuàng)新戰(zhàn)略分析研究報(bào)告
- 培訓(xùn)機(jī)構(gòu)動態(tài)定價(jià)制度
- 培訓(xùn)機(jī)構(gòu)培訓(xùn)門衛(wèi)制度
- 酒店培訓(xùn)管理制度
- 近五年河北中考英語試題及答案2025
- 山西省臨汾市2025-2026年八年級上物理期末試卷(含答案)
- (2025年)員工安全培訓(xùn)考試試題(含答案)
- GB/T 36132-2025綠色工廠評價(jià)通則
- 2025-2026學(xué)年北師大版八年級數(shù)學(xué)上冊期末復(fù)習(xí)卷(含答案)
- 2026四川成都九聯(lián)投資集團(tuán)有限公司招聘12人筆試參考題庫及答案解析
- 【二下數(shù)學(xué)】計(jì)算每日一練60天(口算豎式脫式應(yīng)用題)
- 殘疾人服務(wù)與權(quán)益保護(hù)手冊(標(biāo)準(zhǔn)版)
- 2025年1月-12月時(shí)事政治歸納總結(jié)(備考必背)
- 2025年安徽省普通高中學(xué)業(yè)水平合格性考試英語試卷(含答案)
- (高清版)DG∕TJ 08-2068-2019 超高壓噴射注漿技術(shù)標(biāo)準(zhǔn)
評論
0/150
提交評論