C语言程序设计实验指导上交大课前练习改错完善程序课后练习参考答案文档格式.docx
《C语言程序设计实验指导上交大课前练习改错完善程序课后练习参考答案文档格式.docx》由会员分享,可在线阅读,更多相关《C语言程序设计实验指导上交大课前练习改错完善程序课后练习参考答案文档格式.docx(33页珍藏版)》请在冰豆网上搜索。
![C语言程序设计实验指导上交大课前练习改错完善程序课后练习参考答案文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/20/863ff447-f7fc-404c-97b0-6aff9128ef8c/863ff447-f7fc-404c-97b0-6aff9128ef8c1.gif)
5.A
7.D
8.B
(1)intx1,x2,x3,x4;
(2)scanf("
%d,%d"
&
a,&
b);
(3)c=x4*1000+x2*100+x3*10+x1;
程序1:
①22
2errorC2065:
'
a1'
:
undeclaredidentifier
变量a1没有定义
sum=a+b+c
③1
errorC2146:
syntaxerror:
missing'
;
'
beforeidentifier'
printf'
printf语句之前缺少分号
sum=a+b+c;
④0error(s),0warning(s)
⑤a=1b=3c=2sum=6
语句以分号结束;
变量要先定义后使用。
程序2:
②errorC2065:
sum'
变量sum没有定义
intsum=a+b;
1
errorC2086:
c'
redefinition
变量c重复定义
c=a+b+sum;
③a=1b=3sum=8
④在同一个函数体内,变量要先定义后使用,但不能重复定义
程序3:
①1
errorC2106:
='
leftoperandmustbel-value
赋值符号左边参数错误
c=a+b;
②c=4
③赋值符号左边只能是变量,不能是常量或表达式
(1)t=a;
(2)a=b;
(3)printf("
a=%d\tb=%d\n"
a,b);
(1)intn
(2)”%d”,&
n
(1)floats
(2)(float)a/b
(3)%f
(1)#include<
math.h>
(2)pow(x,y)
(3)“%lf”,s
4.B
6.D
8.A
9.C
10.A
11.A
12.B
13.B
14.C
15.B
16.A
17.C
18.8
19.5和4
20.2.000000
21.double(删除最后“语句”两字)
22.double
23.a=3(回车)
实验三if选择结构语句
1.90
2.110
(1)n%2==0
(2)n%2!
=0
(3)a>
=’0’&
&
a<
=’9’
(4)a>
=’a’&
=’z’
(5)a>
=’A’&
=’Z’
(6)(a>
=’z’)||(a>
=’Z)
(7)(x<
-10)||((x>
10)&
(x<
=20))
(8)a%b!
(9)a*b>
4.-1
5.D
6.103040
7.C
9.D
(1)scanf("
%d"
t);
(2)if(t%5==0&
t%7==0)
(3)else
(1)chary;
(2)if(x==0)
%c\n"
y);
(1)if(x==m)
(2){printf("
Wrong\n"
);
Toolow\n"
}
math.h>
(2)(-b+sqrt(d))/(2*a);
(3)sqrt(fabs(d))/(2*a);
(1)c>
a'
c<
u'
(2)c>
v'
z'
(3)c=c+5-26;
A'
Z'
2.C
4.A
5.B
8.C
9.B
10.D
12.D
13.D
14.A
15.2,0
17.D
18.A
19.D
20.B
21.C
22.!
23.D
24.C
25.D
26.B
实验四switch开关语句
1.411
2.
if((k==1)||(k==2)
printf("
a\n"
elseif((k==3)||(k==4)||(k==5))
b\n"
else
c\n"
switch(x)
{
case1:
case2:
case3:
printf("
x\n"
break;
case19:
case20:
case21:
y\n"
default:
z\n"
}
(1)switch(x)
(2)case4:
(3)default:
(1)a=s/250;
(2)case0:
d=0;
d=15;
(1)elsep=1;
(2)a=num/1000;
(3)num%10
(1)grade/10
(2)break
(3)default
(1)x<
(2)a=x/10
(3)a
(1)month
(2)days=31
(3)(year%4==0&
year%100!
=0)||(year%400==0)
1.C
2.D(将程序最后一条语句改为:
a=%d,b=%d\n"
)
5.pass中
及格
不及格
6.2
实验五while、do…while循环结构语句
1.0
2.10
6.A
1.
(1)longk=1;
(2)num/=10;
(3)while(num);
2.
(1)intm=0,mc=0,j;
(2)if((k%7==0)||(k%11==0))
(3)m=m+k
3.
(1)max=min=grade;
(2)while(grade>
=0)
(3)if(grade<
min)
(1)t%2==0
(2)m=m*10+t;
(3)n=n/10;
(1)ch=getchar()
(2)ch>
0'
ch<
9'
(3)(ch>
)||(ch>
3.
(1)fabs(t)
(2)s/n
(3)pi*4
1.A
2.A
3.D
7.A
8.30
实验六for循环结构语句
3.C
4.for(i=100;
i!
=0;
i--)printf("
p"
8.k<
=n
k++
9.A
10.C
11.C
(1)intsum=1,s0=0,s1=0,s2=1,s;
(2)for(n=4;
n<
=10;
n++)
(3)s2=s;
(1)for(i=1;
i<
=y;
i++)
(2)t*=x;
(3)t=t%1000;
(1)inti,count=0;
(2)if((i%7==0||i%11==0)&
(i%77!
=0))
(3)count++;
(1)s=0.0
n)
(3)s+1.0/s1
(1)i%100
(2)a+b+c==x
(3)t++
(1)2
(2)n
(3)n%i==0
2.B
实验七循环控制语句
课前习题
2.循环语句
3.break
5.20
6.66
7.8
(1)inti,j,k,sum=0;
(2)for(i=1;
=3;
(3)if((k>
=1&
k<
=6)&
(i!
=0)&
(j!
=0)||(k==0))
(1)for(j=2;
j<
i;
j++)
(2)if(i%j==0)
(3)if(j>
=i)
(1)m=n;
(2)while(m!
=0&
m>
=c)
(3)if(m==0)
(1)i<
10
(2)j%3!
(3)continue;
(1)total=0;
(2)sum=0;
(3)total+sum;
(1)j=(y%100)/10;
(2)i!
=j&
i!
=k&
k!
=j
(3)t%5==0
6.B
8.91
9.107
10.x=16y=8
实验八函数的初步应用
1.voidreturn
5.73
7.D
8.D
(1)intfun(inta,intb,intc)
(2)if(a+b>
c&
b+c>
a&
a+c>
b)
(3)elseif(a==b||b==c||a==c)
(1)if(n==1)
(2)c=age(n-1)+2;
%d\n"
age(5))
(1)while(n!
=i)
(2)if(n%i==0)
(3)n=n/i;
(1)i*i==x
(2)return0
(3)f(i+100)&
f(i+168)
(1)x
(2)s1+s2+s3==15
(1)f<
t
(2)retu