标准C语言程序的设计与应用周纯杰版习题参考答案.docx
- 文档编号:1742917
- 上传时间:2022-10-23
- 格式:DOCX
- 页数:14
- 大小:18.37KB
标准C语言程序的设计与应用周纯杰版习题参考答案.docx
《标准C语言程序的设计与应用周纯杰版习题参考答案.docx》由会员分享,可在线阅读,更多相关《标准C语言程序的设计与应用周纯杰版习题参考答案.docx(14页珍藏版)》请在冰豆网上搜索。
标准C语言程序的设计与应用周纯杰版习题参考答案
注:
以下内容为教材部分习题答案,如发现错误请告知,欢迎讨论——张惕远
习题二
一、选择题
1、C
2、BCD
3、A
4、A(注:
本题强调用户标识符,所以if、int不是,但是sin是用户标识符,原因是库函数不是标准语法成分,开发库函数的程序员也是用户,main虽然不是语法成分,但开发平台预定义了main为consoleapplication的执行入口,并且规定了定义格式,所以用户不能用作它用,但_main可以)
5、(D)(C)
6、C
7、D
8、B
9、A
10、D
11、B(注:
本题是求strlen("\\\”DEF\”\\”)的值,即字符串中有效字符的个数,不含串结尾符,sizeof(“…”)的值与前者不同,含串结尾符)
12、D
13、C
14、D
15、A
16、B
17、A
18、B
二、判断题
(对)(错)(错)(对)
三、填空题
1、B66回车
2、n1=%d\nn2=%d
3、5
四、计算下列各表达式的值
1、注:
本书假设采用16位编译平台,所以int和unsignedint均为2字节类型。
(1)47
(2)38
(3)9
(4)0xFFC6or65478
(5)104
(6)2
2、
(1)6
(2)50
(3)1
(4)-16or0xFFF0
(5)1
(6)20
3、表达式值a的值b的值
(1)053
(2)153
(3)313
(4)15104
(5)883
(6)153
4、表达式值x的值y的值
(1)12252
(2)0243
(3)1243
(4)27243
(5)1243
(6)663
(7)242424(y<<=3)
(8)27243
(9)-29or0xffe3243
以上类型均为int
5、表达式值x的值y的值
(1)001
(2)121
(3)100
(4)-3-33
(5)424
以上类型均为int
五、程序分析题
b=20(注:
中间4个空格)a=3600回车
习题三
一、填空题
1、s=6回车
2、s=96回车
3、
(1)c=getchar()orscanf(“%c”,&c)
(2)c-32orc-‘a’+’A’
习题四
一、写出程序运行结果:
1、no1a=1no1a=0no1a=1no1a=0(注:
教材中关于func函数的原型有错,应该改为:
voidfunc();)
2、a=0b=0c=0
a=1b=0c=0
a=2b=0c=0
3、main:
x=5,y=1,n=1
fun:
x=6,y=21,n=11
main:
x=5,y=1,n=11
fun:
x=8,y=31,n=21
习题五
一、选择题和填空题
1、D
2、D
3、C
4、6
5、CDABC
6、
(1)j+=2
(2)a[j]>a[i]
(注:
教材中for语句有错,应该去掉表达式3后面的分号“;”)
最后输出为unalggace
7、
(1)s[j]
(2)s[j]
8、D
9、B
10、6
11、isdigit(s[i])该带参数的宏用来判断字符s[i]是不是数字字符,该宏的定义在头文件ctype.h中
12、‘\0’和str1[i]-str2[i]
二、1、第7行sum=0;
第10行改为:
scanf(“%d”,&a[i][j]);
习题六
一、选择题
1、D
2、D
3、D
4、C
5、CD
6、D
7、B
8、B
二、填空题
1、*(p+3)222
2、cdefg
bcdefg
abcdefg
7
3、6385
三、程序分析题
9、第5行改为:
p=&s[0];orp=s;
10、第4,5行合为:
doublex,y,*p;
11、第4行改为:
intx,*p=&x;否则p为“野指针”或者在给p赋值之前定义一个int变量y,然后p=&y;
12、第4,5行交换书写次序。
习题七
一、选择题
1、A
2、D
3、B
4、D
5、C
6、A
7、B
二、程序填空题
1、a[k]a[k]a[k]
2、a[i]j6ori+1
三、改错题
1、第3行最后加分号“;”
第4行改为:
voidmain()
第7行去掉三个&运算符
第8,9行改为:
if(strcmp(a,b)>0)swap(a,b);
if(strcmp(b,c)>0)swap(b,c);
if(strcmp(a,b)>0)swap(a,b);
swap函数改为:
voidswap(char*pstr1,char*pstr2)
{
charp[80];//千万不能用char*p;没有赋初值即为“野指针”,危险!
strcpy(p,pstr1);
strcpy(pstr1,pstr2);
strcpy(pstr2,p);
}
2、第1行后面加入:
floatprocess(float*,int,int*);
voidmain()
intm;定义后加入:
floatmax;
process定义改为:
floatprocess(…)
{
…
floattemp=p1[0];或改为:
=*p1
*p2=p1[0];//插入
for(x=1;x … } 四、编程题 //P.230第七章习题 //编程题4参考程序答案 // // // // #include voiddelete_char(char*s,charc); voidmain() { charstr[80],ch; puts("请输入一个不足79个字符的串: "); scanf("%s",str); getchar(); puts("请输入待删除的字符: "); scanf("%c",&ch); delete_char(str,ch); printf("删除特定字符%c后的字符串为%s\n",ch,str); } voiddelete_char(char*s,charc) { char*p; p=s; for(;*s;s++) if(*s! =c)*p++=*s; *p='\0'; } //P.230第七章习题 //编程题8参考程序答案 // // // // /* #include #include #include //#include voidreverse(char*s); intlen;//全局变量使得reverse函数通用性降低 voidmain() { char*str; str=(char*)malloc(80*sizeof(char)); if(! str)//if(str==NULL) puts("内存空间不够! "); puts("请输入待翻转的字符串: "); scanf("%s",str);//gets(str); len=strlen(str); reverse(str); printf("翻转后的字符串为: %s\n",str); free(str);//很重要,必须与前面的malloc配对,编程时,最好习惯性地在写 //完malloc后马上先把free写上,免得遗忘 } voidreverse(char*s) { chartemp; if(len==2||len==3) { temp=*s; *s=*(s+len-1); *(s+len-1)=temp; } else { temp=*s; *s=*(s+len-1); *(s+len-1)=temp; len-=2; reverse(s+1); } }*/ //---------------------------------------------------------------- //下面是通用性强的reverse函数 #include #include #include //#include voidreverse(char*s,intlen); voidmain() { char*str; intlength; str=(char*)malloc(80*sizeof(char)); if(! str)//if(str==NULL) puts("内存空间不够! "); puts("请输入待翻转的字符串: "); scanf("%s",str); length=strlen(str); reverse(str,length); printf("翻转后的字符串为: %s\n",str); free(str); } voidreverse(char*s,intlen) { chartemp; if(len==2||len==3) { temp=*s; *s=*(s+len-1); *(s+len-1)=temp; } else { temp=*s; *s=*(s+len-1); *(s+len-1)=temp; len-=2; reverse(s+1,len); } } //P.230第七章习题 //编程题15参考程序答案 // // //本例可以采用结构体数组 // #include #include voidinput(int[],char[][20],int[],int[][4]); voidcalcu(int[][4],float[],float*); voidsort(int[],char[][20],int[],int[][4],float[]); voidoutput(int[],char[][20],int[],int[][4],float[],float); voidmain() { intscore[30][4]; floatavg[30],total_avg; charname[30][20]; intid[30],sex[30]; input(id,name,sex,score); calcu(score,avg,&total_avg); sort(id,name,sex,score,avg); output(id,name,s
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 标准 语言 程序 设计 应用 周纯杰版 习题 参考答案