经典c程序阅读(8).doc

上传人:pu****.1 文档编号:549144055 上传时间:2023-06-16 格式:DOC 页数:9 大小:31.01KB
返回 下载 相关 举报
经典c程序阅读(8).doc_第1页
第1页 / 共9页
经典c程序阅读(8).doc_第2页
第2页 / 共9页
经典c程序阅读(8).doc_第3页
第3页 / 共9页
经典c程序阅读(8).doc_第4页
第4页 / 共9页
经典c程序阅读(8).doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《经典c程序阅读(8).doc》由会员分享,可在线阅读,更多相关《经典c程序阅读(8).doc(9页珍藏版)》请在金锄头文库上搜索。

1、经典c程序100例=71-80【程序71】题目:编写input()和output()函数输入,输出5个学生的数据记录。1.程序分析:2.程序源代码:#define N 5struct student char num6;char name8;int score4; stuN;input(stu)struct student stu; int i,j;for(i=0;iN;i+) printf(n please input %d of %dn,i+1,N);printf(num: );scanf(%s,stui.num);printf(name: );scanf(%s,stui.name);fo

2、r(j=0;j3;j+) printf(score %d.,j+1);scanf(%d,&stui.scorej);printf(n);print(stu)struct student stu; int i,j;printf(nNo. Name Sco1 Sco2 Sco3n);for(i=0;iN;i+) printf(%-6s%-10s,stui.num,stui.name);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

3、=head;while(ptr!=NULL) printf(The value is =%dn,ptr-data);ptr=ptr-next;=【程序73】题目:反向输出一个链表。1.程序分析:2.程序源代码:/*reverse output a list*/#include stdlib.h#include stdio.hstruct list int data;struct list *next;typedef struct list node;typedef node *link;void main() link ptr,head,tail;int num,i;tail=(link)ma

4、lloc(sizeof(node);tail-next=NULL;ptr=tail;printf(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) printf(The value is =%dn,ptr-data);ptr=ptr-next;=【程序74】题目:连接两个链表。1.程序分析:2.程序源代码:#include stdlib.h#include stdio.hstruct list

5、int data;struct list *next;typedef struct list node;typedef node *link;link delete_node(link pointer,link tmp)if (tmp=NULL) /*delete first node*/return pointer-next;else if(tmp-next-next=NULL)/*delete last node*/tmp-next=NULL;else /*delete the other node*/tmp-next=tmp-next-next;return pointer;void s

6、election_sort(link pointer,int num) link tmp,btmp;int i,min;for(i=0;idata;btmp=NULL;while(tmp-next) if(mintmp-next-data)min=tmp-next-data;btmp=tmp;tmp=tmp-next;printf(40: %dn,min);pointer=delete_node(pointer,btmp);link create_list(int array,int num) link tmp1,tmp2,pointer;int i;pointer=(link)malloc(

7、sizeof(node);pointer-data=array0;tmp1=pointer;for(i=1;inext=NULL;tmp2-data=arrayi;tmp1-next=tmp2;tmp1=tmp1-next;return pointer;link concatenate(link pointer1,link pointer2) link tmp;tmp=pointer1;while(tmp-next)tmp=tmp-next;tmp-next=pointer2;return pointer1;void main(void) int arr1=3,12,8,9,11;link p

8、tr;ptr=create_list(arr1,5);selection_sort(ptr,5);=【程序75】题目:放松一下,算一道简单的题目。1.程序分析:2.程序源代码:main()int i,n;for(i=1;i1)break;if(n%2=0)printf(Even=);sum=dcall(peven,n);elseprintf(Odd=);sum=dcall(podd,n);printf(%f,sum);float peven(int n)float s;int i;s=1;for(i=2;i=n;i+=2)s+=1/(float)i;return(s);float podd(n

9、)int n;float s;int i;s=0;for(i=1;i=n;i+=2)s+=1/(float)i;return(s);float dcall(fp,n)float (*fp)();int n;float s;s=(*fp)(n);return(s);=【程序77】题目:填空练习(指向指针的指针)1.程序分析:2.程序源代码:main() char *s=man,woman,girl,boy,sister;char *q;int k;for(k=0;k5;k+);/*这里填写什么语句*/printf(%sn,*q);=【程序78】题目:找到年龄最大的人,并输出。请找出程序中有什么问题。1.程序分析:2.程序源代码:#define N 4#include stdio.hstatic struct man char name20;int age; personN=li,18,w

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号