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

上传人:zw****58 文档编号:41039393 上传时间:2018-05-28 格式:DOC 页数:7 大小:54KB
返回 下载 相关 举报
《C语言程序设计》第6章习题答案_第1页
第1页 / 共7页
《C语言程序设计》第6章习题答案_第2页
第2页 / 共7页
《C语言程序设计》第6章习题答案_第3页
第3页 / 共7页
《C语言程序设计》第6章习题答案_第4页
第4页 / 共7页
《C语言程序设计》第6章习题答案_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《《C语言程序设计》第6章习题答案》由会员分享,可在线阅读,更多相关《《C语言程序设计》第6章习题答案(7页珍藏版)》请在金锄头文库上搜索。

1、1 1、选择题、选择题(1)A(2)C(3)A(4)B(5)B(6)D(7)D(8)B(9)D(10)B2 2、填空题、填空题(1)a=10,b=20 a=20,b=10(2)*pp=603 3、程序设计题、程序设计题(1)#includechar *month_name(int n);void main()int n;printf(“nPlease enter 1 integer:“);scanf(“%d“,printf(“%d month :%sn“,n,month_name(n);char *month_name(int n)static char*name=“illegal month

2、“, “Jan“,“Feb“,“Mar“,“Apr“,“May“,“Jun“, “July“,“Aug“,“Sept“,“Oct“,“Nov“,“Dec“;return (n12)?name0:namen);(2)#include#define N 10sort(int data)int i,j,min_a,temp;for(i=0;ivoid reverse(char *c);void main()char str80;puts(“Please enter 1 stringn“);gets(str);reverse(str) ;puts(“After reversedn“);puts(str

3、);void reverse(char *c)char *p,*q,temp;int size=0;for(p=c;*p!=0;p+)size+;size=size/2;for(q=c,p-;q#includevoid sort(char *keyword,int size);void print(char *keyword,int size)void main()char *keyword=“if“,“else“,“case“,“switch“,“do“,“whlie“,“for“,“break“,“continue“;sort(keyword,9);print(keyword,9);voi

4、d sort(char *keyword,int size)int i,j,min_location;char *temp;for(i=0;i0)min_location=j;if(min_location!=i)temp=keywordi;keywordi=keywordmin_location;keywordmin_location=temp;void print(char *keyword,int size)int i;for(i=0;i void fun_char(char str1,char str2,char str3); void main() char str180,str28

5、0,str380,c,i;printf(“nPlease enter 2 string:“);scanf(“%s%s“,str1,str2); fun_char(str1,str2,str3);printf(“Third string is %s.“,str3); void fun_char(char *str1,char *str2,char *str3) int i,j,k,flag;i=0,k=0;while(*(str1+i)!=0)j=0;flag=1;while(*(str2+j)!=0j+;if(flag)*(str3+k)=*(str1+i); k+;i+;*(str3+k)=

6、0; (6) #include int count_word(char *str); void main() char str180,c,res;puts(“nPlease enter a string:“);gets(str1);printf(“There are %d words in this sentence“,count_word(str1); int count_word(char *str) int count ,flag;char *p;count=0;flag=0;p=str;while(*p!=0)if(*p= )flag=0;else if(flag=0)flag=1;c

7、ount+;p+;return count; (7) #include #include char *encrypt(char *string); char *decrypt(char *string); main() char item80;char *point;char *pEncrypted;char *pDecrype;printf(“Please enter the string need to encrypt:n“);gets(item);point=item;pEncrypted=encrypt(point);printf(“nThe string after encrypte

8、d is:n%sn“,pEncrypted);pDecrype=decrypt(pEncrypted);printf(“nThe string after decrypted is:n%sn“,pDecrype);free(pEncrypted);free(pDecrype); char *encrypt(char *string) char *q,*t;q=(char *)malloc(sizeof(char)*80);if(!q)printf(“No place to malloc!“);return 0;t=q;while(*string!=0)*q=*string-2;string+;q+;*q=0;return t; char *decrypt(char *string) char *q,*t;q=(char *)malloc(sizeof(char)*80);if(!q)printf(“No place to malloc!“);return 0; t=q;while(*string!=0)*q=*string+2;string+;q+;*q=0;return t;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 教育学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号