1、1参考答案习题一1、 选择题CBACD2、 填空题1) main()2) main()3) 有穷性、确定性、有效性、0 个到多个输入、1 个到多个输出4) 顺序、选择、循环5) 自顶向下、逐步细化、模块化设计、限制 goto习题二1、 选择题ACCDA DDAAC BBACC2、 填空题1) 字母、数字、下划线2) 03) 4 84) ( a + b ) * c / ( a c )5) -606) -167) 98) 6 4 29) 010) 10 611) 12 412) 3.50000013) 014) 1615) 6.63、编程题/(1)编写一个程序求各种类型数据的存储长度。#inclu
2、de void main()printf(“int:%d byten“,sizeof(int);printf(“short int:%d byten“,sizeof(short int);printf(“long int:%d byten“,sizeof(long int);printf(“float:%d byten“,sizeof(float);printf(“double:%d byten“,sizeof(double);printf(“long double:%d byten“,sizeof(long double);printf(“char:%d byten“,sizeof(char
3、);2#include #define RAT 1.60934void main()float k;printf(“input the km:“);scanf(“%f“,printf(“mile:%fn“,k/RAT);习题三1、 选择题DACDD DCDCC2、 解析题1)#include void main() int x=170;float a=513.789215;printf(“x=%3d,x=%6d,x=%6o,x=%6x,x=%6un“,x,x,x,x,x);printf(“x=%-3d,x=%-6d,x=%6d,x=%6dn“,x,x,x,x);printf(“a=%8.6f,
4、a=%8.2f,a=%14.8f,a=%14.8lfn“,a,a,a,a);结果:x=170,x= 170,x= 252,x= aa,x= 170x=170,x=170 ,x= 170,x=%6da=513.789185,a= 513.79,a= 513.78918457,a= 513.789184572)#include main() int a,b;float x,y;char c1,c2;scanf(“a=%d b=%d“,scanf(“x=%f y=%f“,scanf(“c1=%c c2=%c“,printf(“a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%c“,a,b,
5、x,y,c1,c2);正确输入格式:A=3 b=7x=8.5 y=71.82c1=A c2=a3、 编程题1)#include void main()3int x,y;scanf(“%d%d“,printf(“商数=%d,余数=%d“,x/y,x%y); 2)#include void main()double x,y,z,avg;scanf(“%lf%lf%lf“,avg=(x+y+z)/3;printf(“%.1f“,avg);习题四1、 选择题CCAAD CCABD2、 填空题1) a0printf(“please input a number:“);scanf(“%d“,if(x%2=
6、0) printf(“x is a even number“);else printf(“x is a odd number“);2)#include 4main()int x,y;printf(“please input a number:“);scanf(“%d“,if(x-5 printf(“please input a number:“);scanf(“%d“,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;p
7、rintf(“%d“,m);4)#include main()float price,tax;printf(“please input the price of product:“);scanf(“%f“,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(“%f“,tax);5)#include main()5float score;printf(“please input the score of stud
8、ent:“);scanf(“%f“,if(score=85) printf(“VERY GOOD“);else if(score=60) printf(“GOOD“);else printf(“BAD“);6)#include main () int x,y,z;printf(“input two number:“);scanf(“%d%d“,if(x99 | y99)printf(“input data error!n“);else z=(x/10)*1000+(y/10)*100+(x%10)*10+y%10; printf(“%dn“,z);习题五1、 选择题DCADA DDBDB CA
9、DAC2、 填空题1) fahr celsius=5.0/9*(fahr-32); fahr+=step;2) i=5 j=4 k=63) 3*i-24) y- z*=x 5) 8 5 26) j+ i%j=0 j=i 7) summain() int n,k;float score,sum,ave;/*found*/for(n=1;nmain() int i,j,k,m;for(i=1; imain()double r,eps,temp;int m=1;printf(“nPlease enter a precision: “);scanf(“%lf“,r=0.0;/*found*/temp=
10、1;/*found*/while(temp =eps)r+=temp;temp=(temp*m)/(2*m+1);m+;/*found*/printf(“neps=%lf,Pi=%lfnn“,eps,r*2);4)#include 7main() int m=0,mix=0,n;/*found*/scanf(“%d“,while(n=2) int n=0,max=0,t;scanf(“%d“,do/*found*/t=m%10;/*found*/if(t=0) n+;if(maxmain()int s;float n,t,sum;t=1; sum=0; n=1; s=1.0;while(nma
11、in()int i;long int n=1;for(i=1;imain()int n,i,j;scanf(“%d“,for(i=1;imain()int m,s,i;for(m=2;mmain() int h10,h7,h5;for(h10=0; h10main() int day,x1,x2; day=9; x2=1; while(day0) x1=(x2+1)*2; /第一天的桃子数是第 2 天桃子数加 1 后的 2 倍 x2=x1; day-; printf(“the total is %dn“,x1); 7)#include #includemain() float x,x0,f,f
12、1; x=1.5; /可改为 scanf(“%f“,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(“The root is %8.7fn“,x); 108)#include main() int p,r,n,m,temp;printf(“input two integer n,m:“);scanf(“%d,%d“,if(nnp=n*m; while(m!=0) r=n%m;n=m;m=r;printf(“greatest common divisor is:%dn“,n); /最大公约数printf(“lease common multiple is:%dn“,p/n); /最小公倍数