资源描述:
《C语言程序设计 教学课件 作者 张树粹 孟佳娜习题答案 第3章习题答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第三章习题单项选择题1.C2.B3.B4.D5.A6.B(A.你好B.你好再见晚安C.你好晚安D.你好再见)7.B8.C9.B10.C11.C12.D13.C二、写出程序运行结果1.1202.s=633.01234theloopbreakout.4.freight=58800005.sum=1sum=3sum=9sum=33三、程序填空1.i++i<102.i<100i%3!=03.x!=-1xmain(){floatc,f;printf("inputf=");sc
2、anf("%f",&f);c=(5.0/9.0)*(f-32);printf("%5.2f",c);}2.#includemain(){intx,y;scanf("%d",&x);if(x<0)y=x;elseif(x>=10)y=3*x-11;elsey=2*x-1;printf("x=%d,y=%d",x,y);}3.#includemain(){chargrade;grade=getchar();switch(grade){case'A':printf(">=90");break;case'B':printf("8
3、0~89");break;case'C':printf("70~79");break;case'D':printf("60~69");break;case'E':printf("0~59");}}4.#includevoidmain(){intp,r,n,m,temp;scanf("%d,%d",&n,&m);if(n4、%k==0&&n%k==0)d=k;printf(“%d,%d”,d,p/d);5.#includevoidmain(){intn,a,b,c;for(n=100;n<=999;n++){a=n/100;b=(n-a*100)/10;c=n%10;if(n==a*a*a+b*b*b+c*c*c)printf("%d,",n);}}6.#includemain(){inta,b,c,d,t;scanf("%d,%d,%d,%d",&a,&b,&c,&d);printf("a=%d,b=%d,c=%d,d=%d",a,b,c,d
5、);if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(a>d){t=a;a=d;d=t;}if(b>c){t=b;b=c;c=t;}if(b>d){t=b;b=d;d=t;}if(c>d){t=c;c=d;d=t;}printf("%d,%d,%d,%d",a,b,c,d);}7.#include#includemain(){floate=1.0,t=1,n=1;while(fabs(1/t)>1e-6){e=e+1/t;n=n+1;t=t*n;}printf("e=%f",e);}8.#i
6、nclude"stdio.h"main(){inti,j,k;for(i=0;i<=2;i++){for(j=0;j<=2-i;j++)printf("");for(k=0;k<=2*i;k++)printf("*");printf("");}for(i=0;i<=1;i++){for(j=0;j<=i+1;j++)printf("");for(k=0;k<=3-2*i-1;k++)printf("*");printf("");}}9.#include#includemain(){intm,k,i,n=0;for(m=3;m<
7、=100;m=m+2){k=sqrt(m);for(i=2;i<=k;i++)if(m%i==0)break;if(i>=k+1){printf("%d",m);n=n+1;}if(n%10==0)printf("");}printf("");}10.#includemain(){intd=0,a=2;floatm,s=0;do{a=2*a;m=0.8*a;s=s+m;d++;}while(a<=100);printf("%f",s/d);}