资源描述:
《张毅坤版c语言程序设计部分答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、张毅坤版部分答案习题3.6#includevoidmain(){charx,y;printf("enteraletter:");//x=getchar();scanf("%c",&x);/*if(x<=64
2、
3、x>122
4、
5、(x>=91&&x<=96))printf("%c,%d",x,x);else{if(x>64&&x<=90)y=32+x;elsey=x-32;printf("%c,%d",y,y);}*/if((x>='a'&&x<='z')
6、
7、(x>='A'&&x<='Z')){if(x>='A'&&x<=
8、'Z')y=32+x;elsey=x-32;printf("%c,%d",y,y);}elseprintf("%c,%d",x,x);}第二种方法:#include#includevoidmain(){floatx,y;intk;printf("pleaseinputx=");scanf("%f",&x);if(x<0
9、
10、x>=40)printf("ERROR");elseswitch((int)x/10){case0:y=sin(x);break;case1:y=cos(x);break;case2
11、:y=exp(x)-1;break;case3:y=log(x+1);break;}}习题3.7第一种方法:#include#includevoidmain(){floatx,y;printf("pleaseinputx=");scanf("%f",&x);if(x<0
12、
13、x>=40)printf("ERROR");else{if(x<10)y=sin(x);elseif(x<20)y=cos(x);elseif(x<30)y=exp(x)-1;elsey=log(x+1);printf("y=%f"
14、,y);}}第二种方法:#include#defineP10voidmain(){floats,m,total;printf("inputs,m:");scanf("%f,%f",&s,&m);if(s<0)printf("error");elseif(s>=700&&s<=750)total=P*s*m*0.97;if(s>750&&s<800)total=P*s*m*0.95;elseswitch((int)s/100){case0:;case1:total=P*s*m;break;case2:;case3:;cas
15、e4:total=P*s*m*0.98;break;case5:;case6:P*s*m*0.97;break;case8:;case9:total=P*s*m*0.95;}printf("total=%f",total);}习题3.8#include#defineP10voidmain(){floats,m,total;printf("inputs,m:");scanf("%f,%f",&s,&m);if(s<0)printf("error");elseif(s<250)total=P*s*m;elseif(s<500
16、)total=P*s*m*0.98;elseif(s<750)total=P*s*m*0.97;elseif(s<1000)total=P*s*m*0.95;elseif(s<1500)total=P*s*m*0.92;elsetotal=P*s*m*0.90;printf("total=%.1f",total);}习题5.16#includevoidmain(){inti,n,j,k,s[50];printf("pleaseentertotaln:");scanf("%d",&n);for(i=0;i17、{printf("pleaseenterthe%dnum:",i+1);scanf("%d",&s[i]);}k=s[0];for(i=0;ivoidmain(){inti,j,x,t,n,k,a[100];printf("请输入已知顺序数个数个数n:");scanf("%d",&n);for(i=0;i18、");scanf("%d",&a[i]);}printf("请输入想插入的个数:");scanf("%d",&t);for(i=0;i<=t;i++){printf