参考答案 习题一 1、 选择题 CBACD 2、 填空题 1) main()
2) main()
3) 有穷性、确定性、有效性、0个到多个输入、1个到多个输出 4) 顺序、选择、循环
5) 自顶向下、逐步细化、模块化设计、限制goto
习题二
1、 选择题
ACCDA DDAAC BBACC
2、 填空题
1) 字母、数字、下划线 2) 0
3) 4 8
4) ( a + b ) * c / ( a – c ) 5) -60
6) -16 7) 9
8) 6 4 2 9) 0 10) 10 6 11) 12 4 12) 3.500000 13) 0 14)
16
15) 6.6 3、编程题
//(1)编写一个程序求各种类型数据的存储长度。 #include
printf(\ printf(\ printf(\ printf(\
printf(\ printf(\
}
1
#include
printf(\T);
}
习题三
1、 选择题 DACDD DCDCC 2、 解析题 1)
#include
float a=513.789215;
printf(\ printf(\ printf(\}
结果:
x=170,x= 170,x= 252,x= aa,x= 170
x=170,x=170 ,x= 170,x=m
a=513.789185,a= 513.79,a= 513.78918457,a= 513.78918457
2) #include
char c1,c2;
scanf(\ scanf(\
scanf(\
printf(\,c1,c2); }
正确输入格式:
A=3 b=7x=8.5 y=71.82c1=A c2=a
3、 编程题
1)
#include
2
{
int x,y;
scanf(\
printf(\商数=%d,余数=%d\ }
2) #include
double x,y,z,avg;
scanf(\ avg=(x+y+z)/3; printf(\}
习题四
1、 选择题 CCAAD CCABD
2、 填空题
1)
① a>0&&b>0||a>0&&c>0||b>0&&c>0 ② a5 ④ a<=0
⑤ a%b!=0
2) ① !(x>0) ② 1 ③ !(x>=0&&x<=5) 3) 3 2 2
4) ch>=’A’ && ch<=’Z’ ch=ch-32
5) x>2&&x<=10 x>-1&&x<=2 y= -1
6) a+b>c && b+c>a && a+c>b a==b && c==a 7) x<0 c=x/10 x != -2
3、 编程题 1)
#include
printf(\ scanf(\
if(x%2==0) printf(\ else printf(\} 2)
#include
a==b || b==c || a==c 3
main()
{
int x,y;
printf(\ scanf(\
if(x>-5 && x<0) { y=x; printf(\ } else if(x==0) { y=x-1; printf(\ } else if(x>0 && x<10) { y=x+1; printf(\ } else printf(\}
3)
#include
printf(\ scanf(\ switch(a/10) { case 0: case 1:
case 2:m=1;break; case 3:m=2;break; case 4:m=3;break; case 5:m=4;break; default:m=5;break; }
printf(\}
4)
#include
{
float price,tax;
printf(\ scanf(\
if(price>=10000) tax=price*0.05; else if(price>=5000) tax=price*0.03; else if(price>=1000) tax=price*0.02; else tax=0;
printf(\} 5)
#include
4
float score;
printf(\ scanf(\
if(score>=85) printf(\ else if(score>=60) printf(\ else printf(\}
6)
#include
else
{ z=(x/10)*1000+(y/10)*100+(x)*10+y; printf(\ }
}
习题五 1、 选择题
DCADA DDBDB CADAC 2、 填空题
1) fahr celsius=5.0/9*(fahr-32); fahr+=step; 2) i=5 j=4 k=6 3) 3*i-2
4) y-- z*=x
5) 8 5 2
6) j++ i%j==0 j==i 7) sum #include { int n,k; float score,sum,ave; /**********found**********/ for(n=1;n<=10;n++) { sum=0.0; for(k=1;k<=4;k++) 5 { scanf(\ sum+=score; } /**********found**********/ ave=sum/4; printf(\ } } 2) #include { int i,j,k,m; for(i=1; i<=9; i++) /*********found **********/ for(j=0; j<=9 ; j++) for(k=0; k<=9; k++) { /********* found *********/ m=100*i+10*j+k; if(m==i*i*i+j*j*j+k*k*k) } } 3) #include double r,eps,temp; int m=1; printf(\ scanf(\ r=0.0; /*******found*********/ temp=1; /********found********/ while(temp >=eps) { r+=temp; temp=(temp*m)/(2*m+1); m++; } /********found********/ printf(\} 4) #include printf(\\6 main() { int m=0,mix=0,n; /********found********/ scanf(\ while((n>=2) && (mix<10)) { /*******found*********/ if((n==0) || (n==0)) { m=m+n; mix++; } n--; } printf(\} 5) #include { unsigned m; int n=0,max=0,t; scanf(\ do { /*******found********/ t=m; /*******found********/ if(t==0) n++; if(max /*******found********/ m=m/10; } while(m); printf(\} 4、 编程题 1) #include t=1; sum=0; n=1; s=1.0; while(n<=100) { 7 sum=sum+t; n=n+1; s=-s; t=s/n; } printf(\ } 2) #include int i; long int n=1; for(i=1;i<=10;i++) { n=n*i; printf(i%5==0?\ } } 3) #include int n,i,j; scanf(\ for(i=1;i<=n;i++) { for(j=1;j<=n+i-1;j++) if(j<=n-i) printf(\ else printf(\ printf(\ } } 4) #include int m,s,i; for(m=2;m<1000;m++) { s=0; for(i=1;i if(s==m) { printf(\ for(i=1;i 8 if(m%i==0) printf(\ printf(\ } } } 5) #include int h10,h7,h5; for(h10=0; h10<=8; h10++) for(h7=0; h7<=8; h7++) for(h5=0; h5<=8; h5++) if(h10+h7+h5==8 && h10*10+h7*7+h5*5==53) printf(\ } 6) #include day=9; x2=1; while(day>0) { x1=(x2+1)*2; //第一天的桃子数是第2天桃子数加1后的2倍 x2=x1; day--; } printf(\ } 7) #include x=1.5; //可改为scanf(\ do { x0=x; f=2*x0*x0*x0-4*x0*x0+3*x0-6; f1=6*x0*x0-8*x0+3; // f的导数,即它的切线 x=x0-f/f1; // 切线与x轴的交点 }while(fabs(x-x0)>=1e-5); printf(\ } 9 8) #include { int p,r,n,m,temp; printf(\ scanf(\ if(n { temp=n; n=m; m=temp; } //确保m>n p=n*m; while(m!=0) { r=n%m; n=m; m=r; } printf(\ //最大公约数 printf(\ //最小公倍数 } 10