C语言程序设计教程答案杨路明郭浩志Word下载.docx
《C语言程序设计教程答案杨路明郭浩志Word下载.docx》由会员分享,可在线阅读,更多相关《C语言程序设计教程答案杨路明郭浩志Word下载.docx(75页珍藏版)》请在冰点文库上搜索。
9、标识符必须是字母或下划线开头,大小写字母含义不同。
由数字、字母和下划线组成;
关键字是一种语言中规定具有特定含义的标识符。
关键字不能作为变量或函数名来使用,用户只能根据系统的规定使用它们。
10、选择主菜单File项下拉子菜单中Save项或直接按F2键存盘。
习题2
1、符合C语法规定的常数为:
0x1e、"
ab\n"
、1.e5
2、
(1):
错误如下:
intx,y=5,z=5,aver;
x=7;
aver=(x+y+x)/3;
结果如下:
AVER=5
charc1='
a'
c2='
b'
c3='
c'
;
a=%db=\'
%c\'
\"
end\"
\n"
a,b);
a=3b='
A'
"
end"
aabccabc
3、
4、
(1):
9,11,9,10
3,1,0,0
(3):
11,19,31,1
5、
(1):
9.500000
(4):
90
(5):
10
(6):
(7):
65
(8):
4
(9):
4.500000
(10):
1
(11):
(12):
20
(13):
6、(5)
7、求x的绝对值
8、c>
(max=a>
b?
a:
b)?
c:
max;
9、B
10、D
习题3
1、输入函数scanf的参数错误,应该为:
scanf("
%f"
&
k);
2、|12341234|
3、ff10
4、1,3,1
5、原字符串
左边加空格再加字符串本省,字符个数总和为5个
6、scanf("
%d,%d,%c,%c"
a1,&
a2,&
c1,&
c2);
7、printf("
a+b=%d\n"
a+b);
a-b=%d\n"
a-b);
a*b=%d\n"
a*b);
a/b=%d\n"
a/b);
(float)a/b=%f\n"
(float)a/b);
a%b=%d\n"
a%b);
8、voidmain()
floatr;
floats,c;
pleaseinputthenumber:
);
scanf("
r);
if(r>
=0)
s=3.14*r*r;
c=2*3.14*r;
s=%f,c=%f\n"
s,c);
else
youinputnumberiserror!
9、voidmain()
{
intn;
%d"
n);
if(n>
=100&
&
n<
=999)
%d%d%d"
n%10,(n/10)%10,n/100);
}
10、voidmain()
inti,j,k;
%d,%d,%d"
i,&
j,&
((i%2!
=0?
1:
0)+(j%2!
0)+(k%2!
0))==2?
printf("
YES\n"
):
NO\n"
11、voidmain()
chara;
%c"
a);
%c,%c,%c"
a-1,a,a+1);
12、voidmain()
floata,b,c,s,Area;
%f,%f,%f"
a,&
b,&
c);
if(a+b>
c||a+c>
b||b+c>
a)
s=(a+b+c)/2;
Area=sqrt(s*(s-a)*(s-b)*(s-c));
%f\n"
Area);
youinputthenumberiserror!
习题4
1:
0
2:
20
3:
(x<
30&
x>
20)||(x<
-100)
4:
***a=25,b=14,c=16***
5:
37
6:
if(a<
=b)printf("
1"
elseprintf("
2"
7、
#include<
stdio.h>
voidmain()
{chara,b,t1,t2;
%c,%c"
b);
t1=a>
b;
t2=a<
if((t1-t2)%2==0)printf("
a+1,b+1);
elseprintf("
a-1,b-1);
getch();
8、
{inttemp1=0,temp2=0,x,y,i=1;
Pleaseinput(x,y):
"
%d,%d"
x,&
y);
while((i*y)<
=x)
{if(x==(i*y)){temp1=1;
break;
temp2=i;
i++;
if(temp1)
printf("
%d/%d=%d"
x,y,i);
%d/%d--->
shang=%d,yushu=%d"
x,y,temp2,x-y*temp2);
9、
{floatx,y,m=0,n=0;
%f,%f"
n=(x-2)*(x-2);
m=(y-2)*(y-2);
if((m+n)<
=1)
(%.3f,%.3f)Intheyuan"
x,y);
(%.3f,%.3f)outoftheyuan"
10、
{inttemp=0,month,year;
Pleaseinput(year,month):
year,&
month);
if((year%400==0)||(year%4==0&
year%100!
=0))
temp=1;
if(month==2)
{if(temp)printf("
%dyear%dmonthhave29"
year,month);
elseprintf("
%dyear%dmonthhave28"
elseif(month%2==0)
%dyear%dmonthhave30"
%dyear%dmonthhave31"
11、
switch(a/10)
{case5:
m=4;
case4:
m=3;
case3:
m=2;
case2:
m=1;
default:
m=5;
12、
方法一:
{intx,y;
x);
if(x<
0&
-5)
y=x-1;
elseif(x==0)
y=x;
elseif(x>
x<
8)
y=x+1;
y);
方法二:
8&
{if(x==0)y=x;
elseif(x>
8)y=y=x+1;
elsey=x-1;
Inputerror!
!
方法三:
{intx,y,i;
{if(x==0)i=1;
8)i=2;
elsei=3;
elsei=4;
switch(i)
{case1:
y=x;
case2:
y=x+1;
case3:
y=x-1;
case4:
}getch();
习题5
1、voidmain()
intn,value;
inti,count=0;
floataverage=0;
longintsum=0;
for(i=0;
i<
n;
i++)
scanf("
value);
if(value%2==0)
{
sum+=value;
count++;
}
average=sum/(float)count;
theaverageis%f\n"
average);
2、
#include"
stdio.h"
charch;
intzm=0,sz=0;
ch=getchar();
while(ch!
='
*'
)
if((ch>
&
ch<
Z'
)||(ch>
'
z'
))
zm++;
if(ch>
0'
9'
sz++;
ch=getchar();
zm=%d;
sz=%d\n"
zm,sz);
longi_value;
intsum=0;
inttemp=0;
%ld"
i_value);
if(i_value<
0){printf("
youinputtheintiserror!
return;
for(;
temp=i_value%10;
i_value=i_value/10;
sum+=temp;
%d+"
temp);
if(i_value==0)break;
\b=%d\n"
sum);
4、
.'
))
ch=ch+32;
putchar(ch);
elseif((ch>
ch=ch-32;
else
5、
floatsum=200;
intcount=0;
sum=sum+sum*0.045;
count++;
if(sum>
500)break;
the%dyearslatercomplete!
count);
inti,temp=0,bit=0;
for(i=1;
=999;
if(i%3==0)
temp=i;
for(;
temp!
=0;
{
bit=temp%10;
if(bit==5){printf("
%d,"
i);
temp=temp/10;
}
\b\n"
#include<
intmain(void)
intsteps=29,i=1;
while(steps%7)
steps=(30*++i)-1;
Totalsteps:
%d\n"
steps);
return0;
main()
inti,j,k,n;
thenarcissusnumberis:
for(n=100;
n<
1000;
n++)
{i=n/100;
j=n/10-i*10;
k=n%10;
if(i*i*i+j*j*j+k*k*k==n)printf("
%d\n"
n);
{floati,j,temp,n,sum;
intt;
i=2;
j=1;
sum=0;
t);
for(n=1;
=t;
{sum=sum+i/j;
temp=i;
i=i+j;
j=temp;
2/1+3/2+5/3+8/5+13/8+...=%f\n"
intnWidth,a,b;
nWidth);
for(a=(nWidth%2);
a<
=nWidth;
a+=2)
for(b=0;
b<
nWidth;
b++)
charchOut='
intnleft=(nWidth-a)/2;
intnright=(nWidth+a)/2;
if(b>
=nleft&
nright)
chOut='
chOut);
inti=1,j=1;
for(i=1;
i<
=9;
i++)
for(j=1;
j<
=i;
j++)
%d*%d=%d"
i,j,i*j);
#include"
charc;
//count1是正数的个数
//count2是负数的个数
intcount1=0,count2=0;
//sum1是正数之和
//sum2是负数之和
intsum1=0,sum2=0;
intflage=0;
c=getchar();
while(c!
if(c=='
-'
)flage=1;
if(flage==0)
{sum1+=(c-48);
count1++;
{if(c!
){sum2-=(c-48);
flage=0;
count2++;
}}
c=getchar();
%d,%d\n"
count1,count2);
%f,%f\n"
sum1/count1,sum2/count2);
13、
inti,j;
ints=0;
for(i=100;
s=0;
j<
i-1;
j++)
if(i%j==0)s=s+j;
if(s==i)printf("
%5d"
14、
math.h>
longk=1;
floate=1;
n=1;
clrscr();
while(fabs(1.0/k)>
=0.000001)
n++;
e=e+1.0/k;
k=k*n;
e);
15、
math.h"
{floatx0,x1,x2,f0,f1,f2;
x1=-10;
f1=2*x1*x1*x1-4*x1*x1+3*x1;
x2=10;
f2=2*x2*x2*x2-4*x2*x2+3*x2;
do
{x0=(x1+x2)/2;
f0=2*x0*x0*x0-4*x0*x0+3*x0;
if((f0*f1)<
0)
{x2=x0;
f2=f0;
{x1=x0;
f1=f0;
while(fabs(f0)>
1e-6);
______2*x*x*x-4*x*x+3*x=0______\n"
therootis%f\n"
x0);
习题6
1、
intdivisor(inta,intb)
{intr;
while((r=a%b)!
{a=b;
b=r;
returnb;
intmultiple(inta,intb)
{intd;
d=divisor(a,b);
returna*b/d;
{inta,b,c,d;
intput(a,b):
c=divisor(a,b);
d=multiple(a,b);
\ndivisor=%d\t\tmultiple=%d"
c,d);
voidtongji(chara[])
{intb[3]={0,0,0},i=0;
while(a[i]!
='
\0'
{if((a[i]<
=90&
a[i]>
=65)||(a[i]<
=122&
=97))
b[0]++;
elseif(a[i]<
=57&
=48)
b[1]++;
b[2]++;
zimuhave:
%d;
shuzihave:
qitahave:
%d"
b[0],b[1],b[2]);
{chara[100];
Pleaseinputastring:
gets(a);
tongji(a);
intflower(intn)
{intx=0,i,j,k;
i=(n%10);
j=(n/10%10);
k=(n/100);
x=i*i*i+j*j*j+k*k*k;
if(x==n)return1;
elsereturn0;
void