资源描述:
《《C语言程序设计(何钦铭 颜晖 主编)》习题8答案.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、P173习题8第一题#includeintmain(void){charch;inta[10];inti,j,m;printf("请输入10个整数:");for(i=0;i<10;i++){printf("请输入%d第个数:",i+1);scanf("%d",&a[i]);}printf("请输入A或D:");scanf("%c",&ch);if(ch=='A'){for(i=0;i<9;i++){for(j=i+1;j<10;j++){if(a[i]>a[j]){m=a[i];a[i]=a[j];a[j]=m;}}}}elseif(ch=='D'){for
2、(i=0;i<9;i++){for(j=i+1;j<10;j++){if(a[i]intmain(void){inta[10];inti,j,x;intsearch(intlist[],inti,intx);printf("输入10个整数:");for(i=0;i<10;i++)scanf("%d",&a[i]);printf("输入一个整数x:");scanf("%d",&x);
3、j=0;for(i=0;i<10;i++){if(search(a,i,x)!=-1){j++;printf("%d",search(a,i,x));}else;}if(j==0)printf("-1");return0;}intsearch(intlist[],inti,intx){intj;j=0;if(x==list[i])j++;else;if(j==0)return-1;elsereturni;}第三题#includevoidhouyi(inta[],int*p,intn,intm);intmain(void){inta[20];inti,m,n;pr
4、intf("请输入整数n:");scanf("%d",&n);printf("请输入%d个整数:",n);for(i=0;i5、n-m-1)*(p+i+m)=b[i];else*(p+(i+m)%n)=b[i];}}第四题#includevoidswap2(int*,int*);voidbubble(inta[],intn);intmain(void){intn,a[8];inti;printf("Entern(n<=8):");scanf("%d",&n);printf("Entera[%d]:",n);for(i=0;i6、)printf("%3d",a[i]);return0;}voidbubble(inta[],intn){inti,j,m;staticintb[8];for(i=1;ia[j+1])swap2(&a[j],&a[j+1]);for(m=0;m#include7、ring.h>voidmcopy(char*s,intm);intmain(void){inti,m,l;charstr[100];printf("请输入您要输入的字符串:");gets(str);printf("您将从原字符串的第m位复制新字符串,请输入m:");scanf("%d",&m);printf("复制后,新的字符串为:");mcopy(str,m);return0;}voidmcopy(char*s,intm){printf("%s",s+m-1);}第六题