经典c程序100例==71--80

上传人:子 文档编号:42023447 上传时间:2018-05-31 格式:DOC 页数:12 大小:38KB
返回 下载 相关 举报
经典c程序100例==71--80_第1页
第1页 / 共12页
经典c程序100例==71--80_第2页
第2页 / 共12页
经典c程序100例==71--80_第3页
第3页 / 共12页
经典c程序100例==71--80_第4页
第4页 / 共12页
经典c程序100例==71--80_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《经典c程序100例==71--80》由会员分享,可在线阅读,更多相关《经典c程序100例==71--80(12页珍藏版)》请在金锄头文库上搜索。

1、经典经典 c c 程序程序 100100 例例=71-80=71-80.:.:经典 c 程序 100 例=71-80:.:. 经典 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“);for(i=0;idata=num;ptr-next=(link)malloc

2、(sizeof(node);if(i=4) ptr-next=NULL;else ptr=ptr-next;ptr=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.h“struct list int data;struct list *next;typedef struct list node;typedef

3、node *link;void main() link ptr,head,tail; int num,i;tail=(link)malloc(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

4、】题目:连接两个链表。1.程序分析:2.程序源代码:#include “stdlib.h“#include “stdio.h“struct list 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

5、;else /*delete the other node*/tmp-next=tmp-next-next;return pointer;void selection_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 crea

6、te_list(int array,int num) link tmp1,tmp2,pointer;int i;pointer=(link)malloc(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;

7、tmp-next=pointer2;return pointer1;void main(void) int arr1=3,12,8,9,11;link ptr;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

8、 peven(int n)float s;int i;s=1;for(i=2;iage)q=p+;m=q-age;printf(“%s,%d“,(*q).name,(*q).age);=【程序 79】题目:字符串排序。1.程序分析:2.程序源代码:main()char *str120,*str220,*str320;char swap();printf(“please input three stringsn“);scanf(“%s“,str1);scanf(“%s“,str2);scanf(“%s“,str3);if(strcmp(str1,str2)0) swap(str1,str2);i

9、f(strcmp(str1,str3)0) swap(str1,str3);if(strcmp(str2,str3)0) swap(str2,str3);printf(“after being sortedn“);printf(“%sn%sn%sn“,str1,str2,str3);char swap(p1,p2)char *p1,*p2;char *p20;strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);=【程序 80】题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?1.程序分析:2.程序源代码:main()int i,m,j,k,count;for(i=4;i10000;i+=4) count=0;m=i;for(k=0;k5;k+)j=i/4*5+1;i=j;if(j%4=0)count+;elsebreak;i=m;if(count=4)printf(“%dn“,count);break;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

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