C语言程序设计教程(第三版)课后习题参考答案 张敏霞版_c第三版课后习题答案
C语言程序设计教程(第三版)课后习题参考答案 张敏霞版由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“c第三版课后习题答案”。
附录F 课后题参考答案
习
题1.1 填空题
1.函数
2.主函数main();主函数main()3.主函数main()4.函数首部;函数体 5.{;} 6.顺序结构;选择结构;循环结构 7..c;.obj;.exe 1.2 思考题
1.答:结构化程序设计是指,为使程序具有一个合理的结构以保证程序正确性而规定的一套如何进行程序设计的原则。顺序结构,选择结构,循环结构
2.答:算法是对具体问题求解步骤的一种描述。计算机算法的表达工具通常采用以下几种方法:①用自然语言表示算法;②用流程图表示算法;③用伪代码表示算法;④用程序设计语言表示算法。
3.略 4.略 5.略 1.3 编程题 1.答:
#include “stdio.h” main(){ float a=10, b=20, h=5, s;s=(a+b)*h/2;printf(“s=%f ” , s);} 2.答:
#include “stdio.h” main(){ printf(“******************************”);printf(“* hello world
*”);printf(“******************************”);}
270 C语言程序设计教程(第3版)
习
题2.1 单选题
DBDCA DCABB CA 2.2 填空题
1.2.000000
2.1;0.500000 3.9;2 4.6 5.100;d 6.(1)20
(2)0
7.(1)10;6;4
(2)6;9;15
8.55或 '7' 9.x=4;y=6;z=3;m=463 2.3 改错题(略)
习 3.1 单选题
BDABC ADCAC BBA
3.2 填空题
1.3 2.261 3.10 4.2, 1;互换a,b的值 5.6.6 6.003 7.7 8.5.0,4,c=3 9.i=10,j=20 10.
(1)65
(2)65,A
(3)3.14,123.46
(4)3.141600e+000,1.234560e+002
(5)8765.432100
(6)8.765432e+003
(3)60(3)3;60;83
题
附录F 课后题参考答案
11.a=2b=5x=8.8y=76.34c1=65c2=97 12.%d/%d;%d/%d=%.2fn
271 3.3 改错题(略)3.4 编程题
1.答:
#include “stdio.h” main(){ int x,y;scanf(“%d%d”,&x,&y);printf(“ttxtyn”);printf(“十进制数t%dt%dn”,x,y);printf(“八进制数t%ot%on”,x,y);printf(“十六进制数t%Xt%xn”,x,y);} 2.答:
#include “stdio.h” main(){ char ch;printf(“请输入一个大写英文字母”);scanf(“%c”,&ch);printf(“大写英文字母是%cn”,ch);printf(“它的前导字符是%cn”,ch-1);printf(“它的后续字符是%cn”,ch+1);} 3.答:
#include “stdio.h” main(){ int x,a,b,c,y;printf(“请输入一个三位整数n”);scanf(“%d”,&x);a=x/100;b=(x-a*100)/10;c=x%10;y=c*100+b*10+a;printf(“反向输出该整数:%dn”,y);} } 4.答:
#include “stdio.h” main(){ int hour;double salary, salaryday;scanf(“%d,%lf”, &hour, &salaryday);salary=hour*salaryday-hour*salaryday*0.1;
272 C语言程序设计教程(第3版)
printf(“%8.2lfn”, salary);} 5.答:
#include “stdio.h” main(){ int a,b,c,t;printf(“请输入三个整数n”);scanf(“%d%d%d”,&a,&b,&c);printf(“交换前a=%d,b=%d,c=%dn”,a,b,c);t=a;a=c;c=b;b=t;printf(“交换后a=%d,b=%d,c=%dn”,a,b,c);} 习
题
4.1 单选题
BADDD ACBBB BA 4.2 填空题
1.1 2.(1)a>0 || b>0
(2)x>0 && x
(3)a==1.5 && b==1.5 && c==1.5
4.c=1 5.4 6.1 7.5, 0, 3 8.5 9.123 10.(cvb= ='y'||cvb= ='Y')&&(work>=3||college=='y'|| college=='Y')&&age
(2)1
(3)1
(4)0
(5)1 4.3 改错题(略)4.4 编程题
1.答
#include “stdio.h” #include “math.h” main(){ double a,b,c,p,area;scanf(“%lf%lf%lf”,&a,&b,&c);printf(“三角形的三边为:%.llf,%.1lf,%.1lfn”,a,b,c);if(a+b>c&&a+c>b&&b+c>a){p=(a+b+c)/2;附录F 课后题参考答案
area=sqrt(p*(p-a)*(p-b)*(p-c));printf(“三角形的面积为%.2lfn”,area);} else printf(“不能构成三角形n”);}
273 2.答:
#include “stdio.h” main(){ int x,y;scanf(“%d,%d”,&x,&y);if(x*x+y*y>1000)
printf(“%dn”,(x*x+y*y)/100);else printf(“%dn”,x+y);} 3.答:
#include “stdio.h” #include “math.h” main(){ double x,y;scanf(“%lf”,&x);if(x
y=x*x-sin(x);else if(x
y=pow(2,x)+x;else
y=sqrt(x*x+x+1);printf(“x=%.2lf y=%.2lfn”,x,y);} 4.答:
#include “stdio.h” main(){ long ge,shi,qian,wan,x;
scanf(“%ld”,&x);
wan=x/10000;
qian=x%10000/1000;
shi=x%100/10;
ge=x%10;
if(ge==wan&&shi==qian)/*个位等于万位并且十位等于千位*/
printf(“this number is a huiwenn”);
else
} printf(“this number is not a huiwenn”);5.答:
#include “stdio.h” main(){ float p,w,s,d,f;
274 C语言程序设计教程(第3版)
scanf(“%f,%,%f”,p,s,w);if(s>3000)d=0.15 else if(s>=2000)d=0.1;else if(s>=1000)d=0.08;else if(s>=500)d=0.05;else if(s>=250)d=0.02;else d=0 f=p*w*s*(1-d);printf(“%f”,f);} 6.答:
#include “stdio.h” main(){ int year,money;char x;printf(“是否是本公司产品(y/n):”);scanf(“%c”,&x);if(x=='y'||x=='Y')
{printf(“产品使用的年限:”);
scanf(“%d”,&year);if(year
{ money=200;
printf(“不是本公司产品,产品保修额是:%dn”,money);} } 7.答:
#include “stdio.h” main(){ int money,num1,num2;printf(“请输入取款额(≤2000):”);scanf(“%d”,&money);if(money>2000)printf(“请输入取款额数≤2000!n”);else
if(money%50==0)
{ num1=money/100;
num2=(money-num1*100)/50;
printf(“需支付100元:%d张n”,num1);
printf(“需支付50元:%d张n”,num2);
} else
printf(“输入钱数必须是50的倍数!n”);} 附录F 课后题参考答案
275 习
题5.1 单选题
CDABA ABDDB DBCB 5.2 填空题
1.2 0 2.333
3.(1)i
(2)j%3!=0 4.(1)flag*(float)k/(k+1)或1.0*flag*k/(k+1)5.(1)max=x(2)x!=1
6.(1)x
(2)y=9x 5.3 改错题(略)5.4 编程题
1.答:
1)for循环,其他略
#include “stdio.h” main(){ int i,s=0;for(i=1;i
#include “stdio.h” main(){ int i=1,p=1;double s=1;do { s+=1.0/p;p*=++i;}while(1.0/p>1e-6);printf(“%lf”,s);} 2.答:
#include “stdio.h” main(){ int m,n,t,a,b;scanf(“%d,%d” ,&m,&n);if(m
(2)flag=-flag(3)scanf(“%d”, &x)
((276 C语言程序设计教程(第3版)
{ t=m;m=n;n=t;} a=m;b=n;t=m%n;while(t){ m=n;n=t;t=m%n;} printf(“%d”,n);} 3.答:
#include “stdio.h” main(){ int x,y,s=1;scanf(“%d,%d”,&x,&y);for(;y>0;y--)s*=x;printf(“%d,%d,%dn ”,s%10,s/10%10,s/100%10);} 4.答:
#include “stdio.h” main(){ int x,y,z;for(x=1;x
if((z%3)==0 &&(5*x+3*y+z/3)==100)
printf(“x=%d,y=%d,z=%dn”,x,y,z);} } 5.答:(a)
#include “stdio.h” main(){ int j,k;
for(j=1;j
printf(“****”);printf(“n”);} }(b)
#include “stdio.h” main(){ int j,k;for(j=1;j
printf(“*”);printf(“n”);} } 附录F 课后题参考答案
6.答:
程序分析:利用for循环控制在100~999之间,对每个数分解出个位、十位、百位。
#include main(){
int i,j,k,n;
printf(“water flower'number is:”);
for(n=100;n
{
i=n/100;/*分解出百位*/
j=n/10%10;/*分解出十位*/
k=n%10;/*分解出个位*/
if(n==i*i*i+j*j*j+k*k*k)
{
printf(“%-5d”,n);
}
}
printf(“n”);}
277 7.答:
#include main(){
int x;
for(x=1000;x>=3;x--)
if(x%3==1&&x%5==2&&x%7==3){ printf(“该校的学生人数是:%d人n”,x);break;} } 8.答:
#include main(){ int x=12,i=1;while(1)
{ if((x+20+i)==2*(x+i))break;
i++;} printf(“小明母亲在%d年后比小明的年龄大一倍n”,i);printf(“那时小明年龄是:%d岁,小明母亲年龄是:%d岁n”,x+i,x+20+i);} 习
题6.1 单选题
DBCCB
BDC
278 C语言程序设计教程(第3版)
6.2 填空题
1.c 2.60 3.1000 10 4.16
6.3 编程题
1.答:
#include “stdio.h” #include “math.h” #define F(a)a*a+ sqrt(3*a*a+2*a+1)main(){ float x, f;scanf(“%f”, &x);f=4.5/F(exp(x))+F(cos(x))+F(sqrt(x))/F(x*x);printf(“%fn”, f);} 习
题7.1 单选题
BCADA CCCDA BCBDB 7.2 填空题
1.(1)2 3 4 5
(4)10000
01000
00100
00010
00001
(5)Language(6)Language Programming(2)10010
(3)QuickC
2.(1)j+=2
(2)a[i]>a[j] 3.(1)i=1
(2)x[i1] 7.3 改错题(略)7.4 编程题
1.答:
#define N 10
#include “stdio.h” main()
{ int a[N]={1,2,3,4,5,6,7,8,9,10,osum=0, qsum=0,j;for(j=0;j
else osum+=a[j];printf(“osum=%d,qsum=%dn”, osum,qsum);}
279 2.答:
#define N 10 #include “stdio.h” main(){ int a[N]={10,20,30,40,50,60,70,80,90}, j, k, x;scanf(“%d”,&x);for(j=0;jj;k--)a[k]=a[k-1];a[j]=x;} for(j=0;j
printf(“%d ”,a[j]);} 3.答:
#define M 3 #include “stdio.h” main(){ int a[M][M]={{1,2,3},{2,4,5},{3,5,6}},j,k,flag=1;;for(j=0;j
if(a[j][k]!=a[k][j]){ flag=0;break;} if(flag)printf(“ok”);else printf(“NO”);} 4.答:
#include “stdio.h” #include “string.h” main(){ char c1[10],c2[10],j;gets(c1);gets(c2);for(j=0;(c1[j]==c2[j])&& c1[j] && c2[j];j++);if(c1[j]>c2[j])printf(“%dn”,1);if(c1[j]
#include “stdio.h” #include “string.h” #define M 3 #define N 80 main(){ char a[M][N],j,k,n[5]={0};for(j=0;j
gets(a[j]);
280 C语言程序设计教程(第3版)
for(j=0;j
if(a[j][k]>='A' && a[j][k]
else if(a[j][k]>='a' && a[j][k]
else if(a[j][k]>='0' && a[j][k]
else if(a[j][k]==' ')n[3]++;
else
n[4]++;
for(j=0;j
printf(“%4d”, n[j]);} 习
题8.1 单选题
DBDAC BACCC 8.2 填空题
1.(1)2, 1
(2)10#30#
2.(1)49
(2)2
(4)1, 1, 1, 1, 1
3, 3, 3, 3, 3
(3)FOUR, P(3)2
(4)60(5)1
0
0
0
0
0
0 0
0
0
0 0
0
0
0
0
08.3 改错题(略)8.4 编程题
1.答:
#include “stdio.h” main(){ int n1,n2,n3,t;int *p1,*p2,*p3;printf(“please input 3 number:n1,n2,n3:”);scanf(“%d,%d,%d”,&n1,&n2,&n3);p1=&n1;p2=&n2;p3=&n3;if(*p1>* p2){ t=*p1;*p1=*p2;*p2=t;} if(*p1>*p3){ t=*p1;*p1=*p3;*p3=t;} if(*p2>*p3){ t=*p2;*p2=*p3;*p3=t;} printf(“the sorted numbers are:%d,%d,%dn”,n1,n2,n3);} 附录F 课后题参考答案
2.答:
#include “stdio.h” #define N 3 main(){ int a[N],*p=a;for(;p-a=0;p--)
printf(“%d ”,*p);}
281 3.答:
#include “stdio.h” main(){ int a[10];int j,minl=0,maxl=0;for(j=0;j
scanf(“%d”, a+j);for(j=0;j
{ if(a[maxl]*(a+j))minl=j;} j=a[0];a[0]=a[minl];a[minl]=j;j=a[9];a[9]=a[maxl];a[maxl]=j;for(j=0;j
printf(“%d ”, *(a+j));} 4.答:
输入阵列如下: 11 12
输出阵列如下: 11 10 9#define M 3 #define N 4 #include “stdio.h” main(){ int a[M][N]={1,2,3,4,5,6,7,8,9,10,11,12},k,j,*p=&a[0][0],t;for(k=0,j=M*N-1;k
printf(“n”);
282 } } C语言程序设计教程(第3版)
5.答:
#include “stdio.h” main(){ int len;char str[20],*p=str;printf(“please input a string:n”);scanf(“%s”,str);len=0;while(*p!=' '){
len++;
p++;}
printf(“the string has %d characters.n”,len);} 6.答:
#include “string.h” #include “stdio.h” main(){ char *str1[5],ch[5][20],k,t,j,*c;void sort(char **);for(k=0;k
if(strcmp(*(str1+t),*(str1+j))>0)t=j;
c=*(str1+t);
*(str1+t)=*(str1+k);
*(str1+k)=c;} for(k=0;k
题9.1 单选题
CBBAD DBCCD DCABC BCCBA DCDAB 附录F 课后题参考答案
283 9.2 填空题
1.120 2.x 3.3,2,2,3
4.fac /i 5.8,17 6.9 7.1.0/(i*i)
8.fun-in:30,20,10
fun-end:1015,35,1050
10,20,30 9.012345
10.93636 11.(1)r+b[k] 12.7 5 3 1 9 13.15 14.(1)*x
(2)t 15.(1)' '
(2)n++ 16.024(2)*x 9.3 改错题(略)9.4 编程题
1.答:
void zhuan(){ char ch;while((ch=getchar())!='n'){ if(ch>='a' && ch
double expp(int n){ int k, fac=1;double sum=1;for(k=1;k
int xy3(int x, int y)
284 { int k, num=1;C语言程序设计教程(第3版)
for(k=1;k
int age(int n){ int c;if(n==1)c=10;else c=age(n-1)+2;return c;} 5.答:
#include “stdio.h” main(){ int a,b,c,d;void fun(int a,int b,int *c, int *d);scanf(“%d%d”,&a,&b);fun(a,b,&c,&d);printf(“%d %d”,c,d);} void fun(int a,int b,int *c, int *d){ if(b){ *c=a/b;*d=a%b;} } 6.答:
#include “stdio.h” main(int argc,char *argv[]){ int k;printf(“argc=%dn”,argc);for(k=1;k
题10.1 单选题
CDBBB BBBAD CCBDC
10.2 填空题
1.所有结构体成员所占存储空间的总和 2.与占用存储空间最大的那个成员相等 附录F 课后题参考答案
3.(1)struct satype(2)3
(3)sa.a
(4)9
(5)psa=&sa 4.80 5.struct node 6.0
285 10.3 编程题
1.答:
#include “stdio.h” struct student { long num;
char name[20]; char sex; float score; }; main(){ struct student s[20], temp; int j,k, man=0, woman=0;float summan=0,sumwoman=0, aveman, avewoman; for(k=0;k
{ summan+=s[k].score;man++;} else
{ sumwoman+=s[k].score;woman++;} } aveman=summan/man;
avewoman=sumwoman/woman;printf("%dt%ft%dt%fn",man,aveman,woman,avewoman); for(k=0;k
if(s[j].score
{ temp=s[j];s[j]=s[j+1];s[j+1]=temp;} printf("the sorted numbers:n");for(k=0;k
printf("%ldt%st%ct%5.1fn",s[k].num,s[k].name,s[k].sex,s[k].score); } 习
题11.1 单选题
BADD 11.2 填空题
1.3d3d330 2.(1)28(2)20
(3)0
(4)9
286 3.(1)251 C语言程序设计教程(第3版)
(2)42
(3)209
(4)–295(5)848 习
题12.1 单选题
BCDCA ADA 12.2 填空题
1.rewind(文件指针)2.“d1.dat”,“rb” 3.stdin 4.文本文件;二进制文件 5.(1)“w”
(2)str[i]32
6.fopen 7.Hello 8.(1)“r”
(2)fgetc(fp)
(3)“r”
(3)time++
C语言程序设计教程课后习题答案第一章 C语言程序设计概述 -习题答案1 算法的描述有哪些基本方法?答1、自然语言2、专用工具2 C语言程序的基本结构是怎样的?举一个例子说明。答1......
《C语言程序设计教程》课后习题参考答案习题1 1.(1)编译、链接.exe (2)函数主函数(或main函数) (3)编辑编译链接 2.(1)-(5):DDBBC (6)-(10):ABBBC 3.(1)答:C语言简洁、紧凑,使用方便、灵活;C语言是......
教材习题答案第一章习题一、单项选择题 1.C 2.B 3.B 4.C 5.D 6.A 7.C 8.A二、填空题1.判断条件 2.面向过程编程 3.结构化 4.程序5.面向对象的程序设计语言 6.基本功能操作......
C语言程序设计课后习题参考答案习题一一、单项选择题1、C2、B3、B4、C5、D6、A7、C8、A二、填空题1、判断条件2、面向过程编程3、结构化4、程序5、面向对象方法6、基本功能......
P124 2古典问题:兔子总数(斐波那契数列) #include int main() { int f1=1,f2=1,f,i,k=0; printf("%d\t %d\t",f1,f2); k=k+2; for(i=3;if=f1+f2;printf("%d\t",f);......
