欢迎来到天天文库
浏览记录
ID:55558104
大小:46.00 KB
页数:10页
时间:2020-05-17
《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(i
2、=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",&
3、x);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];int
4、i,m,n;printf("请输入整数n:");scanf("%d",&n);printf("请输入%d个整数:",n);for(i=0;i5、if(i<=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、i=0;ia[j+1])swap2(&a[j],&a[j+1]);for(m=0;m#i7、ncludevoidmcopy(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,int
5、if(i<=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、i=0;ia[j+1])swap2(&a[j],&a[j+1]);for(m=0;m#i7、ncludevoidmcopy(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,int
6、i=0;ia[j+1])swap2(&a[j],&a[j+1]);for(m=0;m#i
7、ncludevoidmcopy(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,int
此文档下载收益归作者所有