• 54.00 KB
  • 2022-04-22 11:48:29 发布

《C语言程序设计》第6章习题答案.doc

  • 7页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'1、选择题(1)A(2)C(3)A(4)B(5)B(6)D(7)D(8)B(9)D(10)B2、填空题(1)a=10,b=20a=20,b=10(2)**pp=603、程序设计题(1)#includechar*month_name(intn);voidmain(){intn;printf("nPleaseenter1integer:");scanf("%d",&n);printf("%dmonth:%sn",n,month_name(n));}char*month_name(intn){staticchar*name[]={"illegalmonth","Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sept","Oct","Nov","Dec"};return((n<1||n>12)?name[0]:name[n]);}(2)#include#defineN10sort(intdata[]){inti,j,min_a,temp; for(i=0;ivoidreverse(char*c);voidmain() {charstr[80];puts("Pleaseenter1stringn");gets(str);reverse(str);puts("Afterreversedn");puts(str);}voidreverse(char*c){char*p,*q,temp;intsize=0;for(p=c;*p!="";p++)size++;size=size/2;for(q=c,p--;q#includevoidsort(char*keyword[],intsize);voidprint(char*keyword[],intsize)voidmain(){char*keyword[]={"if","else","case","switch","do","whlie", "for","break","continue"};sort(keyword,9);print(keyword,9);}voidsort(char*keyword[],intsize){inti,j,min_location;char*temp;for(i=0;i0)min_location=j;if(min_location!=i){temp=keyword[i];keyword[i]=keyword[min_location];keyword[min_location]=temp;}}}voidprint(char*keyword[],intsize){inti;for(i=0;ivoidfun_char(charstr1[],charstr2[],charstr3[]);voidmain(){charstr1[80],str2[80],str3[80],c,i;printf("nPleaseenter2string:");scanf("%s%s",str1,str2);fun_char(str1,str2,str3);printf("Thirdstringis%s.",str3);}voidfun_char(char*str1,char*str2,char*str3){inti,j,k,flag;i=0,k=0;while(*(str1+i)!=""){j=0;flag=1;while(*(str2+j)!=""&&flag==1){if(*(str2+j)==*(str1+i))flag=0;j++;}if(flag){*(str3+k)=*(str1+i);k++;}i++;}*(str3+k)="";}(6)#includeintcount_word(char*str);voidmain(){charstr1[80],c,res;puts("nPleaseenterastring:");gets(str1);printf("Thereare%dwordsinthissentence",count_word(str1));}intcount_word(char*str){intcount,flag;char*p;count=0; flag=0;p=str;while(*p!=""){if(*p=="")flag=0;elseif(flag==0){flag=1;count++;}p++;}returncount;}(7)#include#includechar*encrypt(char*string);char*decrypt(char*string);main(){charitem[80];char*point;char*pEncrypted;char*pDecrype;printf("Pleaseenterthestringneedtoencrypt:n");gets(item);point=item;pEncrypted=encrypt(point);printf("nThestringafterencryptedis:n%sn",pEncrypted);pDecrype=decrypt(pEncrypted);printf("nThestringafterdecryptedis:n%sn",pDecrype);free(pEncrypted);free(pDecrype);}char*encrypt(char*string){char*q,*t;q=(char*)malloc(sizeof(char)*80);if(!q){printf("Noplacetomalloc!");return0; }t=q;while(*string!=""){*q=*string-2;string++;q++;}*q="";returnt;}char*decrypt(char*string){char*q,*t;q=(char*)malloc(sizeof(char)*80);if(!q){printf("Noplacetomalloc!");return0;}t=q;while(*string!=""){*q=*string+2;string++;q++;}*q="";returnt;}'