y;//<->为表示交换的双目运算符,以下同if(y<"> y;//<->为表示交换的双目运算符,以下同if(y<" />
欢迎来到天天文库
浏览记录
ID:39199239
大小:197.00 KB
页数:75页
时间:2019-06-27
《数据结构习题集答案(c版)(清华大学 严蔚敏)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.16voidprint_descending(intx,inty,intz)//按从大到小顺序输出三个数{scanf("%d,%d,%d",&x,&y,&z);if(xy;//<->为表示交换的双目运算符,以下同if(yz;if(xy;//冒泡排序printf("%d%d%d",x,y,z);}//print_descending1.17Statusfib(intk,intm,int&f)//求k阶斐波那契序列的第m项的值f{inttempd;if(k<2
2、
3、m<0)returnERROR;if(m4、0;elseif(m==k-1)f=1;else{for(i=0;i<=k-2;i++)temp=0;temp[k-1]=1;//初始化for(i=k;i<=m;i++)//求出序列第k至第m个元素的值{sum=0;for(j=i-k;j5、um{male,female}gender;charschoolname;//校名为'A','B','C','D'或'E'char*result;intscore;}resulttype;typedefstruct{intmalescore;intfemalescore;inttotalscore;}scoretype;voidsummary(resulttyperesult[])//求各校的男女总分和团体总分,假设结果已经储存在result[]数组中{scoretypescore;i=0;while(result.sport!=NULL){switch(r6、esult.schoolname){case'A':score[0].totalscore+=result.score;if(result.gender==0)score[0].malescore+=result.score;elsescore[0].femalescore+=result.score;break;case'B':score.totalscore+=result.score;if(result.gender==0)score.malescore+=result.score;elsescore.femalescore+=result.score7、;break;……?……?……}i++;}for(i=0;i<5;i++){printf("School%d:",i);printf("Totalscoreofmale:%d",score.malescore);printf("Totalscoreoffemale:%d",score.femalescore);printf("Totalscoreofall:%d",score.totalscore);}}//summary1.19Statusalgo119(inta[ARRSIZE])//求i!*2^i序列的值且不超过maxint{las8、t=1;for(i=1;i<=ARRSIZE;i++){a[i-1]=last*2*i;if((a[i-1]/last)!=(2*i))reurnOVERFLOW;last=a[i-1];returnOK;}}//algo119分析:当某一项的结果超过了maxint时,它除以前面一项的商会发生异常.1.20voidpolyvalue(){floatad;float*p=a;printf("Inputnumberofterms:");scanf("%d",&n);printf("Inputthe%dcoefficientsfroma0toa%d:",n,n9、);for(i=0;i<=n;i++)scanf("%f",p++);printf("Inputvalueofx:");scanf("%f",&x);p=a;xp=1;sum=0;//xp用于存放x的i次方for(i=0;i<=n;i++){sum+=xp*(*p++);xp*=x;}printf("Valueis:%f",sum);}//polyvalue2.10StatusDeleteK(SqList&a,inti,intk)//删除线性表a中第i个元素起的k个元素{if(i<110、11、k<012、13、i+k-1>a.length)returnINFEASIBLE14、;for(count=1;i+count-1<=a.
4、0;elseif(m==k-1)f=1;else{for(i=0;i<=k-2;i++)temp=0;temp[k-1]=1;//初始化for(i=k;i<=m;i++)//求出序列第k至第m个元素的值{sum=0;for(j=i-k;j
5、um{male,female}gender;charschoolname;//校名为'A','B','C','D'或'E'char*result;intscore;}resulttype;typedefstruct{intmalescore;intfemalescore;inttotalscore;}scoretype;voidsummary(resulttyperesult[])//求各校的男女总分和团体总分,假设结果已经储存在result[]数组中{scoretypescore;i=0;while(result.sport!=NULL){switch(r
6、esult.schoolname){case'A':score[0].totalscore+=result.score;if(result.gender==0)score[0].malescore+=result.score;elsescore[0].femalescore+=result.score;break;case'B':score.totalscore+=result.score;if(result.gender==0)score.malescore+=result.score;elsescore.femalescore+=result.score
7、;break;……?……?……}i++;}for(i=0;i<5;i++){printf("School%d:",i);printf("Totalscoreofmale:%d",score.malescore);printf("Totalscoreoffemale:%d",score.femalescore);printf("Totalscoreofall:%d",score.totalscore);}}//summary1.19Statusalgo119(inta[ARRSIZE])//求i!*2^i序列的值且不超过maxint{las
8、t=1;for(i=1;i<=ARRSIZE;i++){a[i-1]=last*2*i;if((a[i-1]/last)!=(2*i))reurnOVERFLOW;last=a[i-1];returnOK;}}//algo119分析:当某一项的结果超过了maxint时,它除以前面一项的商会发生异常.1.20voidpolyvalue(){floatad;float*p=a;printf("Inputnumberofterms:");scanf("%d",&n);printf("Inputthe%dcoefficientsfroma0toa%d:",n,n
9、);for(i=0;i<=n;i++)scanf("%f",p++);printf("Inputvalueofx:");scanf("%f",&x);p=a;xp=1;sum=0;//xp用于存放x的i次方for(i=0;i<=n;i++){sum+=xp*(*p++);xp*=x;}printf("Valueis:%f",sum);}//polyvalue2.10StatusDeleteK(SqList&a,inti,intk)//删除线性表a中第i个元素起的k个元素{if(i<1
10、
11、k<0
12、
13、i+k-1>a.length)returnINFEASIBLE
14、;for(count=1;i+count-1<=a.
此文档下载收益归作者所有