經(jīng)典程序百例100例_第1頁
經(jīng)典程序百例100例_第2頁
經(jīng)典程序百例100例_第3頁
經(jīng)典程序百例100例_第4頁
經(jīng)典程序百例100例_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、經(jīng)典 c 程序 100 例=71-80【程序 71】題目:編寫 input()和 output()函數(shù)輸入,輸出 5 個學(xué)生的數(shù)據(jù)程序分析:程序源代碼: #define N 5 struct student char num6; char name8;score4; stuN; input(stu)struct student stu;i,j; for(i=0;iN;i+)。 prprf(n please input %d of %dn,i+1,N);f(num: );scanf(%s,stui.num);prf(name: );scanf(%s,);for(j=0;j3;j

2、+) prf(score %d.,j+1);scanf(%d,&stui.scorej);prf(n);pr(stu)struct student stu;pri,j;f(nNo. Name Sco1 Sco2 Sco3n);for(i=0;iN;i+) prf(%-6s%-10s,stui.num,);for(j=0;jn);for(i=0;idata=num;ptr-next=(link)malloc(sizeof(node); if(i=4) ptr-next=NULL;else ptr=ptr-next;ptr=head; while(ptr!=NULL) prf(T

3、he value is =%dn,ptr-data);ptr=ptr-next;=【程序 73】題目:反向輸出一個鏈表。程序分析:程序源代碼:/*reverse output a list*/ #include stdlib.h #include stdio.h struct listdata;struct list *next;typedef struct list node; typedef node *link;void main() link ptr,head,tail; num,i;tail=(link)malloc(sizeof(node); tail-next=NULL;ptr=

4、tail;prf(nplease input 5 data=n);for(i=0;idata=num;head=(link)malloc(sizeof(node); head-next=ptr;ptr=head;ptr=ptr-next; while(ptr!=NULL) prf(The value is =%dn,ptr-data);ptr=ptr-next;=【程序 74】題目:連接兩個鏈表。程序分析:程序源代碼: #include stdlib.h #include stdio.h struct listdata;struct list *next;typedef struct list

5、 node; typedef node *link;link delete_nink poif (tmp=NULL) /*deleteer,link tmp)node*/return poelseer-next; if(tmp-next-next=NULL)/*deletmp-next=NULL;ast node*/else /*delete the other node*/tmp-next=tmp-next-next;return poer;void selection_sort(link poer,num)link tmp,btmp; i,min;for(i=0;idata;btmp=NU

6、LL;while(tmp-next) if(mmp-next-data)mmp-next-data;btmp=tmp;tmp=tmp-next;pr polinkf(40: %dn,min);er=delete_node(poer,btmp);create_list(array,num) link tmp1,tmp2,poi;er;popoer=(link)malloc(sizeof(node);er-data=array0;tmp1=poer;for(i=1;inext=NULL;tmp2-data=arrayi; tmp1-next=tmp2; tmp1=tmp1-next;return

7、poer;link concatenaink po link tmp;er1,link poer2)tmp=poer1;while(tmp-next)tmp=tmp-next;tmp-next=poer2;return poer1;void main(void)arr1=3,12,8,9,11;link ptr; ptr=create_list(arr1,5); selection_sort(ptr,5);=【程序 75】題目:放松一下,算一道簡單的題目。程序分析:程序源代碼: main()i,n; for(i=1;i1)break; if(n%2=0)prf(Even=);sum=dcall

8、(peven,n);elseprf(Odd=);sum=dcall(podd,n);prf(%f,sum);float peven(float s;i; s=1;n)for(i=2;i=n;i+=2) s+=1/(float)i;return(s);float podd(n)n;float s;i; s=0;for(i=1;i=n;i+=2) s+=1/(float)i;return(s);float dcall(fp,n) float (*fp)();n;float s; s=(*fp)(n);return(s);=【程序 77】題目:填空練習(xí)(指向指針的指針)程序分析:程序源代碼: mai

9、n() char *s=man,woman,girl,boy,sister; char *q;k;for(k=0;k5;k+);/*這里填寫什么語句*/f(%sn,*q);pr=【程序 78】題目:找到最大的人,并輸出。請找出程序中程序分析:程序源代碼: #define N 4 #include stdio.h問題。sic struct man char name20;age;N=li,18,wang,19,zhang,20,sun,22;main()struct man *q,*p; i,m=0;p=;for (i=0;iN;i+)if(mage) q=p+;m=q-age;prf(%s,%

10、d,(*q).name,(*q).age);=【程序 79】題目:字符串排序。程序分析:程序源代碼: main()charchar pr*str120,*str220,*str320; swap();f(please input three stringsn);scanf(%s,str1);scanf(%s,str2);scanf(%s,str3); if(strcmp(str1,str2)0) swap(str1,str2); if(strcmp(str1,str3)0) swap(str1,str3); if(strcmp(str2,str3)0) swap(str2,str3);pr prchar charcharf(after being sortedn);f(%sn%sn%sn,str1,str2,str3);swap(p1,p2)*p1,*p2;*p20;strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);=【程序 80】題目:海灘上有一堆桃子,五只猴子來分。第一只猴子把這堆桃子憑據(jù)分為五份,多了一個,這只猴子把多的一個扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一個,它同樣把多的一個扔入海中,拿走了一份,第三、第四、第五只猴子都是這樣做的,問海灘上

溫馨提示

  • 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論