C语言程序的设计第三版课后复习题答案Word格式文档下载.docx

上传人:b****6 文档编号:21454047 上传时间:2023-01-30 格式:DOCX 页数:87 大小:31.69KB
下载 相关 举报
C语言程序的设计第三版课后复习题答案Word格式文档下载.docx_第1页
第1页 / 共87页
C语言程序的设计第三版课后复习题答案Word格式文档下载.docx_第2页
第2页 / 共87页
C语言程序的设计第三版课后复习题答案Word格式文档下载.docx_第3页
第3页 / 共87页
C语言程序的设计第三版课后复习题答案Word格式文档下载.docx_第4页
第4页 / 共87页
C语言程序的设计第三版课后复习题答案Word格式文档下载.docx_第5页
第5页 / 共87页
点击查看更多>>
下载资源
资源描述

C语言程序的设计第三版课后复习题答案Word格式文档下载.docx

《C语言程序的设计第三版课后复习题答案Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C语言程序的设计第三版课后复习题答案Word格式文档下载.docx(87页珍藏版)》请在冰豆网上搜索。

C语言程序的设计第三版课后复习题答案Word格式文档下载.docx

if(a>

b)max=a;

elsemax=b;

if(max<

c)max=c;

最大的数为:

%d\n\n"

max);

5-5

floatx,y;

输入x\n\n"

x);

if(x<

1)y=x;

elseif(x<

10)y=2*x-1;

elsey=3*x-11;

y=%f\n\n"

y);

5-6

floatm;

intn;

输入成绩\n\n"

m);

n=m/10;

switch(n)

case0:

case1:

case2:

case3:

case4:

case5:

E\n\n"

break;

case6:

D\n\n"

case7:

C\n\n"

case8:

B\n\n"

case9:

case10:

A\n\n"

5-7

math.h>

inta,b,c,i,j,n;

输入五位正整数\n\n"

scanf("

%d"

a);

\n\n"

c=a;

for(i=1;

;

i++)

{b=c%10;

c=c/10;

printf("

b);

if(c==0){printf("

正整数为%d位数\n\n”,i);

for(j=i-1;

j>

=0;

j--)

{n=pow(10,j);

b=c/n;

c=c%n;

%d\n"

5-8

if语句:

intI;

floatbonus;

输入当月利润I\n\n"

I);

if(I<

=100000)bonus=I/10;

elseif(I<

=200000)bonus=10000+(I-100000)*7.5/100;

=400000)bonus=10000+7500+(I-200000)*5/100;

=600000)bonus=10000+7500+10000+(I-400000)*3/100;

=1000000)

bonus=10000+7500+10000+6000+(I-600000)*1.5/100;

elsebonus=10000+7500+10000+6000+6000+(I-1000000)*1/100;

应发奖金数为:

bonus);

switch语句:

if(I>

1000000)n=10;

elsen=I/100000;

bonus=I/10;

bonus=10000+(I-100000)*7.5/100;

bonus=10000+7500+(I-200000)*5/100;

bonus=10000+7500+10000+(I-400000)*3/100;

bonus=10000+7500+10000+6000+6000+(I-1000000)*1/100;

5-9

inta,b,c,d,temp,min;

输入四个数a,b,c,d\n\n"

%d%d%d%d"

c,&

d);

b)

temp=a;

a=b;

b=temp;

c)

a=c;

c=temp;

}if(a>

d)

a=d;

d=temp;

由小到大排列为:

%d"

a);

if(b>

temp=b;

b=c;

}if(b>

b=d;

if(c>

temp=c;

c=d;

d);

#include<

floatx,y,a,b,c,d;

输入点的坐标\n\n"

x,&

y);

a=sqrt((2-x)*(2-x)+(2-y)*(2-y));

b=sqrt((2-x)*(2-x)+(-2-y)*(-2-y));

c=sqrt((-2-x)*(-2-x)+(-2-y)*(-2-y));

d=sqrt((-2-x)*(-2-x)+(2-y)*(2-y));

10m"

if(a<

=1||b<

=1||c<

=1||d<

=1)printf("

该点建筑高度为:

elseprintf("

0m"

6-1

intm,n,max,min,i,k;

输入两个正整数\n\n"

%d%d"

m,&

n);

if(m>

n)k=n;

elsek=m;

i<

=k;

{if((m%i==0)&

&

(n%i==0))max=i;

最大公约数为:

n)k=m;

elsek=n;

for(i=k;

if((i%m==0)&

(i%n==0))

min=i;

最小公倍数为:

min);

6-2

charc;

intl=0,b=0,n=0,e=0;

输入一行字符\n\n"

while((c=getchar())!

='

\n'

{if((c>

a'

c<

z'

)||(c>

A'

Z'

))l+=1;

elseif(c=='

'

)b+=1;

elseif(c>

=48&

=57)n+=1;

elsee+=1;

英文字母个数为:

%d\n\n空格个数为:

%d\n\n数字个数为:

%d\n\n其他字符个数为:

l,b,n,e);

6-3

intn,k,i;

floata,s=0;

输入n和a\n\n"

%d%f"

n,&

for(i=0;

n;

k=pow(10,i);

s=s+(n-i)*a*k;

和s=%f\n\n"

s);

6-4

intn,s,S=0,i,j;

输入n\n\n"

j<

=n;

s=1;

for(j=1;

=i;

j++)

s=s*j;

S+=s;

和S=%d\n\n"

S);

6-5#include<

inti,m,n,t;

ints1=0,s2=0;

floats3=0,s,l;

输入m,n,t的值\n\n"

t);

=m;

s1+=i;

s2+=i*i;

=t;

l=1.0/i;

s3+=l;

s=s1+s2+s3;

和s=%f"

6-6

intm,n,k,i,j;

水仙花数为:

\n"

for(i=100;

=999;

j=i;

m=j%10;

j=j/10;

n=j%10;

k=j/10;

if(i==m*m*m+n*n*n+k*k*k)printf("

i);

6-7#include<

inti,j,k,s;

=1000;

{s=0;

i;

if(i%j==0)s+=j;

}if(s==i)

%ditsfactorsare"

for(j=1;

j++){

if(i%j==0)printf("

j);

6-8

{floatf1,f2,s,temp;

f1=2.0;

f2=3.0;

s=f1;

=n-1;

s+=f2/f1;

temp=f2;

f2=f1+f2;

f1=temp;

printf(”前%4项和为%f"

n,s);

6-9

inti,n,l=100;

floatm,s=0;

m=l;

s+=2*m;

m=m*0.5;

第%d次落地时经过%f米\n\n"

n,s-l);

第%4次落地后反弹%f米\n\n"

n,m);

intm=1,n,i;

m=(m+1)*2;

printf(”一共摘了%d个桃子\n\n”,m);

6-11

floata,x1,x2;

输入a\n\n"

x1=a/2;

loop:

x2=(x1+a/x1)/2;

if(fabs(x1-x2)>

1e-5){x1=x2;

gotoloop;

elseprintf("

\n\na的平方根为%f\n\n"

x2);

floatf(float);

floatxpoint(float,float);

floatroot(float,float);

floatx,x1,x2,f1,f2;

do

输入x1,x2\n\n"

x1,&

x2);

f1=f(x1);

f2=f(x2);

}while(f1*f2>

0);

x=root(x1,x2);

%f\n\n"

x);

方程在1.5附近的根为:

floatf(floatx)

floaty;

y=2*x*x*x-4*x*x+3*x-6;

return(y);

floatxpoint(floatx1,floatx2)

y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));

floatroot(floatx1,floatx2)

floatx,y,y1;

y1=f(x1);

x=xpoint(x1,x2);

y=f(x);

if(y*y1>

0)

y1=y;

x1=x;

else

x2=x;

}while(fabs(y)>

1e-4);

return(x);

6-13

f1=f(x1);

方程的根为:

{y=f((x1+x2)/2);

if(y<

-1e-4){x1=(x1+x2)/2;

elseif(y>

1e-4)

{x2=(x1+x2)/2;

elsex=(x1+x2)/2;

6-14

inti,j,k;

=3;

"

{for(j=0;

=2-i;

}for(k=0;

k<

=2*i;

k++)

*"

}printf("

\n"

}for(i=0;

=2;

for(j=0;

{printf("

for(k=0;

=4-2*i;

6-15

chari,j,k;

for(i='

X'

for(j='

if(i!

=j)

for(k='

=k&

j!

=k)

k!

)printf("

\nA--%c\nB--%c\nC--%c\n"

i,j,k);

第七章

7-1

inti,j;

inta[101];

素数为:

\n\n"

for(i=1;

=100;

a[i]=i;

}for(i=3;

{for(j=2;

=sqrt(a[i]);

if(a[i]%j==0)

a[i]=0;

for(i=2;

if(a[i]!

=0)printf("

a[i]);

7-2#include<

inta[10],i,j,temp;

输入10个整数\n\n"

10;

a[i]);

for(j=i+1;

if(a[i]>

a[j])

temp=a[i];

a[i]=a[j];

a[j]=temp;

排序后的输出为:

7-3

inta[9],i,s=0;

输入一个3*3整型矩阵\n\n"

for(i=0;

9;

{scanf("

i+=4)

{s+=a[i];

对角线元素之和为:

7-4

inta[11]={1,2,3,4,5,6,7,8,9,10};

inti,j,n,temp1,temp2;

输入一个数n\n\n"

if((a[0]-a[9])>

if(n<

=a[9])

a[10]=n;

if(a[i]<

n)

temp1=a[i];

a[i]=n;

11;

temp2=a[j];

a[j]=temp1;

temp1=temp2;

}break;

if((a[9]-a[0])>

if(n>

7-5

#defineN5

inta[N];

inti,temp;

输入5个个数\n\n"

N;

=N/2;

a[i]=a[N-i-1];

a[N-i-1]=temp;

7-6#include<

stdio.h>

inta[10][10]={1};

a[i][0]=a[i-1][0];

a[i][j]=a[i-1][j-1]+a[i-1][j];

%4d"

a[i][j]);

7-7#include<

#defineN7voidmain()

inta[N][N]={0};

i=0;

j=(N-1)/2;

a[i][j]=1;

for(k=2;

=N*N;

k++){

i=i-1;

j=j+1;

if((i<

0)&

(j>

N-1))

i=i+2;

j=j-1;

if(i<

0)i=N-1;

if(j>

N

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 环境科学食品科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1