第1章
1.选择题
(1) C (2) B (3) D
2.填空题
(1)main (2) main (3) 有穷性、确定性、有零个或多个输入、有一个或多个输出、有效性(4) 顺序、分支和循环(5) 自顶向下,逐步细化、模块化设计、结构化编码
第2章
1.选择题
BBCDA DDBBA BBDCB
2、填空题
(1) 数字、字母、下划线 (2)0 (3) 4、8 (4) (a+b)*c/(a-b) (5) -60 (6)-16 (7)3 (8)6、4、2 (9)0 (10)10、6 (11)5.500000 (12) 12、4
(13)double (14) 0 (15)16 (16)6.6
3、编程题
(1)
main()
{
printf("int:%5d\n"
"float:%5d\n"
"char:%5d\n"
"double:%5d\n"
"long:%5d\n",
sizeof(int),+-
sizeof(float),
sizeof(char),
sizeof(double),
sizeof(long));
}
(2)
#define RAT 1.60934
main()
{
float k=0.0;
printf("input the km:");
scanf("%f",&k);
printf("\nmile:%f",k*RAT);c语言程序设计教材答案
}
第3章
1.选择题
(1) ~(10):DDCDCDCDBC
2.解析题
(1) x=170,x=ㄩㄩㄩ170,x=ㄩㄩㄩ252, x=ㄩㄩㄩ170
x=170,x=170ㄩㄩㄩ,x=ㄩㄩㄩ170,x=%6d
a=513.789185,a=ㄩㄩ513.79,a=513.78918457,a=513.78918457 (2) a=3ㄩb=7x=8.5ㄩy=71.82c1=Aㄩc2=a
3.编程题
(1)
main()
{
int x,y;
scanf("%d%d",&x,&y);
printf("商数=%d,余数=%d",x/y,x%y);
system("pause");
}
(2)
main()
{
double x,y,z,avg;
scanf("%lf%lf%lf",&x,&y,&z);
avg=(x+y+z)/3;
printf("%.1lf",avg,avg);
system("pause");
}
第4章
1.选择题
(1)~(10) CCAADCCABD
2.填空题
(1) ch>='A' && ch<='Z' ch=ch-32
(2) x<=10 && x>2 x<=2 && x>-1 y=-1
(3) a+b>c && a+c>b && b+c>a a==b&&a==c a==b || a==c || b==c
(4) mark/10 k=1 case 9
(5) x<0 c=x/10 y!=-2
3.编程题
(1)
#include <stdio.h>
main()
{
int x;
printf("please input a number:");
scanf("%d",&x);
if(x%2==0) printf("x is a even number");
else printf("x is a odd number");
}
(2)
#include <stdio.h>
main()
{
int x,y;
printf("please input a number£o");
scanf("%d",&x);
if(x<=-5) printf("the number is error");
else if(x<0) {y=x; printf("%d",y);}
else if(x==0) {y=x-1;printf("%d",y);}
else if(x<10) {y=x+1;printf("%d",y);}
else printf("the number is error");
}
(3)
#include <stdio.h>
main()
{ int a,m;
printf("please input a number:");
scanf("%d",&a);
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("%d",m);
}
(4)
#include <stdio.h>
main()
{
float price,tax;
printf("please input the price of product:"); scanf("%f",&price);
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 <stdio.h>
main()
{
float score;
printf("please input the score of student:");
scanf("%f",&score);
if(score>=85) printf("VERY GOOD");
else if(score>=60) printf("GOOD");
else printf("BAD");
}
第5章
1.选择题
(1)d (2) c (3)a (4)d (5)a (6)d (7)d (8)b (9)d (10)b (11)c (12)b (13)d (14)a (15)c
2.填空题
(1) ==0 m=m/k k++ (2) 5 4 6 (3) 3*i-2
(4) -= *= (5) 8 5 2 (6) j++ i%j==0 j>=i
(7)sum<k sum==k j-2 (8) s=0 p=1 j<=i
3.改错题
(1) 第一处改正: For改为for
第二处改正: ave=sum/4改为ave=sum/4.0
(2) 第一处改正: j<=9
第二处改正: m=100*i+10*j+k
3.编程题
(1)
#include <math.h>
main()
{
int s;
float n,t,sum;
t=1; sum=0; n=1; s=1.0;
while(n<=100)
{
sum=sum+t;
n=n+1;
s=-s;
t=s/n;
}
printf("sum=%10.6f\n",sum);
}
(2) 利用辗除法,直到b为0为止
main()
{ int p,r,n,m,temp;
printf("input two integer n,m:");
scanf("%d,%d",&n,&m);
if(n<m)
{ temp=n;
n=m;
m=temp;
}
p=n*m;
while(m!=0)
{
r=n%m;
n=m;
m=r;
}
printf("greatest common divisor is:%d\n",n); //最大公约数printf("lease common multiple is:%d\n",p/n); //最小公倍数
}
(3) 采取逆向思维的方法,从后往前推断。
main()
{
int day,x1,x2;
day=9;
x2=1;
while(day>0)
{ x1=(x2+1)*2; /*第一天的桃子数是第2天桃子数加1后的2倍*/ x2=x1;
day--;
}
printf("the total is %d\n",x1);
}
(4)
#include <stdio.h>
main()
{
int i;
long int n=1;
for(i=1;i<=10;i++)
{
n=n*i;
printf(i%5==0?"%2d!=%-10ld\n":"%2d!=%-10ld",i,n);
}
}
(5)
main()
{
int m,s,i;
for(m=2;m<1000;m++)
{ s=0;
for(i=1;i<m;i++)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论