资源描述:
《C语言程序设计(第3版)-丁亚涛.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、《C语言程序设计(第3版)》丁亚涛教材习题与解答习题1【参考答案】1.C语言基本特点:简洁、紧促、灵活、运算符丰富、数据结构丰富、移植性好等。2.程序如下:#includevoidmain(){printf("Thisismyfirstcprogram.");}3.C语言源程序文件扩展名为.c,目标文件扩展名为.obj,可执行文件扩展名为.exe习题2【参考答案】一、单选题1.C2.B3.A4.C5.A6.D7.D8.B9.D10.D11.C12.C二、阅读程序题1.10,10,9,
2、102.j=1,i=2k=3,i=3j=3,i=2k=1,i=1i+j=11,++j=6习题3【参考答案】一、单选题:1.D2.C3.D4.B5.A6.B7.C8.A9.C10.B二、阅读程序,写出程序运行结果1.□□6□□6□6.00□6.002.x=127,x=□□□127,x=177,x=7fy=123.4567,y=□□123.46,y=123.456703.2,14.12345.4,36.-6,-6三、程序设计1.参考程序:#include#includevoi
3、dmain(){floata,b,c,d,x1,x2;a=2;b=-3;c=-5;d=b*b-4*a*c;x1=(-b+sqrt(d))/(2*a);x2=(-b+sqrt(d))/(2*a);printf("x1=%.2f,x2=%.2f",x1,x2);}2.参考程序:#include#includevoidmain(){floata,v,s;scanf("%f",&a);v=pow(a,3);s=6*a*a;printf("v=%.2f,s=%.2f",v,
4、s);}3.参考程序:#includevoidmain(){inta,b,c,t;scanf("%d,%d,%d",&a,&b,&c);printf("a=%d,b=%d,c=%d",a,b,c);t=c;c=b;b=a;a=t;printf("a=%d,b=%d,c=%d",a,b,c);}4.参考程序:#includevoidmain(){chars1,s2;s1=getchar();s2=s1-32;printf("%c",s2);}习题4【参考答案】
5、一、单选题1.C2.D3.D4.B5.A6.D7.D8.B9.C10.A11.B12.D13.D14.C15.C16.B17.B18.C二、阅读程序题1.a=2,b=12.c=1三、程序设计题1.参考程序#includevoidmain(){inta,b;charc;printf("INPUTA+(-*/)B");scanf("%d%c%d",&a,&c,&b);switch(c){case'+':printf("%d+%d=%d",a,b,a+b);break;case'-':
6、printf("%d-%d=%d",a,b,a-b);break;case'*':printf("%d*%d=%d",a,b,a*b);break;case'/':printf("%d/%d=%d",a,b,a/b);break;default:printf("INPUTERROR!");}}2.参考程序#includevoidmain(){floatx,y;scanf("%f",&x);if(x==0
7、
8、x==2)y=0;elseif(x>0)y=(x+1)/(x-2);e
9、lsey=(x-1)/(x-2);printf("y=%f",y);}3.参考程序#includevoidmain(){intscore;printf("Enterascore:");scanf("%d",&score);printf("score=%d:",score);switch(score/10){case10:printf("A");break;case9:printf("B");break;case8:printf("C");break;case7:printf(
10、"D");break;case6:printf("E");break;default:printf("F");}}4.参考程序#includevoidmain(){intx,n;scanf("%d",&x);n=0;if(x<=0
11、
12、x>=10000)printf("DataError!");else{if(x<10)n=1;elseif(x<100)n=2;elseif(x<1000)n=3