资源描述:
《南航C语言课后习题07答案.pdf》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、习题7答案1.答案#includeintmerge(inta[],intb[],intc[],intm,intn){inti=0,j=0,k=0;while(i2、,5);printf("arraya:");for(i=0;i<4;i++)printf("%4d",a[i]);printf("");printf("arrayb:");for(i=0;i<5;i++)printf("%4d",b[i]);printf("");printf("mergedarrayc:");for(i=0;ivoidcount(inta[],intb[],intm){
3、inti,k;for(i=0;i0){b[k%10]++;k=k/10;}}}main(){inta[]={23,12,40,3,8,9,34,55,66},b[10]={0},i;count(a,b,9);for(i=0;i<10;i++)printf("%d:%d",i,b[i]);}3.答案#includeintpalin(intk){inti,j=0,a[10];while(k>0){a[j++]=k%10;k=k/10;}for(i=0;i4、+){if(a[i]!=a[j-i-1])return0;}return1;}main(){intk,x;printf("Pleaseinputaninteger:");scanf("%d",&x);k=palin(x);if(k)printf("%dispalindrome.",x);elseprintf("%disnotpalindrome.",x);}4.答案#includeintisvowel(charc){if(c=='a'
5、
6、c=='e'
7、
8、c=='i'
9、
10、c=='o'
11、
12、c=='u'
13、
14、
15、c=='A'
16、
17、c=='E'
18、
19、c=='I'
20、
21、c=='O'
22、
23、c=='U')return1;elsereturn0;}main(){chars[80];inti=0,sum=0;printf("Pleaseinputastring:");scanf("%s",s);while(s[i]){if(isvowel(s[i]))sum++;i++;}printf("thenumberofvowel:%d",sum);}5.答案#includeintDtoH(intn,intc[]){inti;for(
24、i=0;n;i++){c[i]=n%16;n/=16;}returni-1;}main(){charh[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};intc[20],n,i;printf("Pleaseinputadecimalnumber:");scanf("%d",&n);i=DtoH(n,c);for(;i>=0;i--)printf("%c",h[c[i]]);printf("");}6.答案#include25、io.h>voidinput(inta[],intn)/*输入*/{inti;printf("Pleaseinput%dnumbers:",n);for(i=0;i26、],intn)/*输出*/{inti;for(i=0;i