1、,stui.name);for(j=0;j=4;scanf(num);ptr-data=num;next=(link)malloc(sizeof(node);if(i=4) ptr-next=NULL;else ptr=ptr-next;while(ptr!=NULL)The value is =%dn,ptr-data);ptr=ptr-【程序73】反向输出一个链表。/*reverse output a list*/struct list *next; link ptr,head,tail;int num,i;tail=(link)malloc(sizeof(node);tail-ptr=t
2、ail;nplease input 5 data=ptr-head=(link)malloc(sizeof(node);head-next=ptr;ptr=head;ptr=ptr-【程序74】连接两个链表。link delete_node(link pointer,link tmp)if (tmp=NULL) /*delete first node*/return pointer-else if(tmp-next-next=NULL)/*delete last node*/tmp-else /*delete the other node*/next=tmp-return pointer;vo
3、id selection_sort(link pointer,int num) link tmp,btmp;int i,min;num;tmp=pointer;min=tmp-data;btmp=NULL;while(tmp-next) if(mintmp-data)min=tmp-btmp=tmp;tmp=tmp-40: %dn,min);pointer=delete_node(pointer,btmp);link create_list(int array,int num) link tmp1,tmp2,pointer;int i;pointer=(link)malloc(sizeof(n
4、ode);pointer-data=array0;tmp1=pointer;for(i=1; tmp2=(link)malloc(sizeof(node);tmp2-data=arrayi;tmp1-next=tmp2;tmp1=tmp1-return pointer;link concatenate(link pointer1,link pointer2) link tmp;tmp=pointer1;while(tmp-next=pointer2;return pointer1;void main(void) int arr1=3,12,8,9,11;link ptr;ptr=create_
5、list(arr1,5);selection_sort(ptr,5);【程序75】放松一下,算一道简单的题目。int i,n;5; n=0;if(i!=1)n=n+1;if(i=3)if(i=4)=4)if(n=3)zhu hao shi de shi:%c,64+i);【程序76】编写一个函数,输入n为偶数时,调用函数求1/2+1/4+.+1/n,当输入n为奇数时,调用函数1/1+1/3+.+1/n(利用指针函数)float peven(),podd(),dcall();float sum;int n;while (1)n);if(n1)break;if(n%2=0)Even=sum=dca
6、ll(peven,n);Odd=sum=dcall(podd,n);%f,sum);float peven(int n)float s;s=1;for(i=2;=n;i+=2)s+=1/(float)i;return(s);float podd(n)s=0;float dcall(fp,n)float (*fp)();s=(*fp)(n);【程序77】填空练习(指向指针的指针) char *s=man,womangirlboysisterchar *q;int k;for(k=0;kk+);/*这里填写什么语句*/%sn,*q);【程序78】找到年龄最大的人,并输出。请找出程序中有什么问题。#
7、define N 4static struct man char name20;int age; personN=li,18,wang,19,zhang,20,sun,22;struct man *q,*p;int i,m=0;p=person;for (i=0;if(mage)q=p+;m=q-age;%s,%d,(*q).name,(*q).age);【程序79】字符串排序。char *str120,*str220,*str320;char swap();please input three stringsnscanf(,str1);,str2);,str3);if(strcmp(str1
8、,str2)0) swap(str1,str2);if(strcmp(str1,str3)0) swap(str1,str3);if(strcmp(str2,str3)0) swap(str2,str3);after being sortedn%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】海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?int i,m,j,k,count;for(i=4;10000;i+=4) count=0;m=i;j=i/4*5+1;i=j;if(j%4=0)count+;elsei=m;if(count=4)printf(,count);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1