C语言程序设计课后习题答案_第1页
C语言程序设计课后习题答案_第2页
C语言程序设计课后习题答案_第3页
C语言程序设计课后习题答案_第4页
C语言程序设计课后习题答案_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1-5

floata[10];

#include<stdio.h>inti;

intmain()floatmax;

(for(i=0;i<10;i++)

printf(u*************************'n\n").(

printf("VeryGood!\n\n");scanf("%f",&a[i]);

printf(“*************************\n”).)

return0;max=a[0];

}for(i=l;i<10;i++)

1-6(

if(max<a[i])

#include<stdio.h>(

intmain()max=a[i];

()

intazb,c,max;)

printf("pleaseinputa,b,c:\n");printf("max=%.lf\n",max);

scanf("%d,%d,%d",&a,&b,&c);return0;

max=a;)

if(max<b)

243

max=b;

if(max<c)/include<stdio.h>

max=c;intmain()

printf(HThelargestnumber{

is%d\n",max);floata,b,c,t;

return0;scanf(,,%f,%f,%f",&a,&b,&c);

)if(a>b)

2-4.1(

t=a;

include<stdio.h>a=b;

#include<string.h>b=t;

intmain()}

(if(a>c)

chara[5]="酱油,b[5]="醋,c[5];(

strcpy(cza);t=a;

strcpy(a,b);a=c;

strcpy(b,c);c=t;

,,

printf("a=%s,b=%s\n,a,b);)

return0;if(b>c)

)(

t=b;

2-4.2

b=c;

#include<stdio.h>c=t;

intmain())

printf(“%5.2f,%5.2f,%5.2f\n“,a,b,c);r0=0.0072;

return0;pl=p*((l+r5)*5);

}p2=p*(l+2*r2)*(l+3*r3);

p3=p*(l+3*r3)*(l+2*r2);

p4=p*pow(l+rl,5);

include<stdio.h>p5=p*pow(l+r0/4,4*5);

intmain()printf("pl=%f\n",pl);

(printf("p2=%f\n",p2);

inti,t;printf("p3=%f\n",p3);

t=l;printf("p4=%f\n",p4);

i=2;printf("p5=%f\n",p5);

while(i<=100)return0;

()

t=t+i;

3-3

i=i+l;

)#include<stdio.h>

printf("%d\n”,t);#include<math.h>

return0;intmain()

floatd=300000,p=6000,r=0.01,m;

m=loglO(p/(p-d*r))/loglO(l+r);

#include<stdio.h>printf("m=%6.1f\n"/m);

#include<math.h>return0;

intmain())

(

3-5

floatpjn;

r=0.1;#include<stdio.h>

n=10;intmain()

p=pow(l+cn);{

printf("p=%f\n"/p);inta,b;

return0;floatx,y;

}charcl,c2;

scanf(Ha=%db=%d",&a,&b);

scanf("%f%e",&x,&y);

#include<stdio.h>scanf("%c%c",&cl,&c2);

#include<math.h>printf("a=%d/b=%dzx=%f,y=%f,cl=%c,c2

intmain()%c\n",a,b,x,y,cl,c2);

(return0;

floatr5,r3,r2jl,r0,p,pl,p2,p3,p4,p5;)

p=1000;

r5=0.0585;

「3=0.054;

r2=0.0468;

rl=0.0414;

chargrade;

3-6

printf("请输入学生成绩

#include<stdio.h>scanf(“%f”,&score);

intmain()while(score>10011score<0)

((

,,,,,,,,

charcl=C'/c2=h/c3='i/c4=n,c5=a;printf("\n输入有误,请重输)

cl=cl+4;scanf("%f”,&score);

c2=c2+4;)

c3=c3+4;switch((int)(score/10))

c4=c4+4;(

c5=c5+4;case10:

printf("passwordcase9:grade='A';break;

,,

is%c%c%c%c%c\n/cl/c2,c3,c4,c5);case8:grade='B';break;

return0;case7:grade='C';break;

)case6:grade='D';break;

case5:

3-7

case4:

#include<stdio.h>case3:

intmain()case2:

(case1:

floathjl,s,sq,vq,vz;case0:grade='E,;

floatpi=3.141526;)

(”请输入圆半径圆柱高成绩是相应的等级

printfr,h:“);printf("%5.1fz

,,,

scanf(%t%f'/&r,&h);是%(:\|1",score,grade);

l=2*pj*r;return0;

s=r*r*pi;)

sq=4*pi*r*r;

4-9

vq=3.0/4.0*pi*r*r*r;

vz=pi*r*r*h;#include<stdio.h>

printf(“圆周长为:l=%6.2f\n”,l);#include<math.h>

printf("圆面积为:s=%6.2f\n",s);intmain()

printfC圆球表面积为:{

sq=%6.2f\nH,sq);int

printf("圆球体积为:numjndi^ten,hundred,thousandzten_thousan

vq=%6.2f\n",vq);d,place;

printf("圆柱体积为:printf("请输入一个整数(0-99999):");

vz=%6.2f\nH,vz);scanf("%d”,&num);

return0;if(num>9999)

place=5;

4-8

elseif(num>999)

#include<stdio.h>place=4;

intmain()elseif(num>99)

{place=3;

floatscore;elseif(num>9)

',

place=2;casel:printf(%d"/indiv);

elseplace=l;printf("\n反序数字为

位数:,

printf(“%d\n",place);printf("%d\n'/indiv);

printf("每位数字为break;

ten_thousand=num/10000;)

return0;

thousand=(int)(num-ten_thousand*10000)/1)

000;

4-10

hundred=(int)(num-ten_thousand*10000-thoinclude<stdio.h>

usand*1000)/100;intmain()

|

ten=(int)(num-ten_thousand*10000-thousaninti;

d*1000-hundred*100)/10;double

bonus,bonl,bon2zbon4,bon6,bonl0;

indiv=(int)(num-ten_thousand*10000-thousaintbranch;

nd*1000-hundred*100-ten*10);bonl=100000*0.1;

switch(place)bon2=bonl+100000*0.075;

{casebon4=bon2+100000*0.05;

5:printf(”%d,%d,%d,%d,%cT,ten_thousand,thbon6=bon4+100000*0.03;

ousand,hundred,tenJndiv);bonl0=bon6+400000*0.015;

printf("\n反序数字为:");printf(“请输入利润i:");

scanf("%d",&i);

,,

printf(%d%d%d%d%d\n"Jndiv/ten,hundred,1branch=i/100000;

housand,ten_thousand);if(branch>10)branch=10;

break;switch(branch)

case(

4:printf("%d,%d,%d,%cT,thousand,hundred,tecase0:bonus=i*0.1;break;

njndiv);case1

printf("\n反序数字为:");bonus=bonl+(i-100000)*0.075;break;

case2:

printf("%d%d%d%d\n",indiv/ten,hundred/thocase3

usand);bonus=bon2+(i-200000)*0.05;break;

break;case4:

casecase5

3:printf("%d,%d,%cT,hundred,ten,indiv);bonus=bon4+(i-400000)*0.03;break;

printf("\n反序数字为:");case6:

case7:

printf("%d%d%d\n",indiv,ten,hundred);case8:

break;case9

case2:printf("%d,%d”,ten,indiv);bonus=bon6+(i-600000)*0.015;break;

printf("\n反序数字为:");case10

printf("%d%d\n",indiv,ten);bonus=bonl0+(i-1000000)*0.01;break;

break;)

printf("奖金是:%10.2f\n",bonus);{t=a;a=b;b=t;}

return0;if(a>c)

}{t=a;a=c;c=t;}

if(a>d)

4-10

{t=a;a=d;d=t;}

include<stdio.h>if(b>c)

intmain(){t=b;b=c;c=t;}

(if(b>d)

inti;{t=b;b=d;d=t;}

doubleif(c>d)

bonus,bonl,bon2,bon4,bon6,bonl0;{t=c;c=d;d=t;}

bonl=100000*0.1;printf("排序结果如下:\n下

bon2=bonl+100000*0.075;printf("%d%d%d%d\n”,a,b,c,d);

bon4=bon2+100000*0.05;return0;

bon6=bon4+100000*0.03;}

bonl0=bon6+400000*0.015;

4-12

printf("请输入利润i:");

scanf("%d",&i);#include<stdio.h>

if(i<=100000)intmain()

bonus=i*0.1;{

elseif(i<=200000)inth=10;

bonus=bonl+(i-100000)*0.075;float

elseif(i<=400000)xl=2,yl=2zx2=-2zy2=2/x3=-2zy3=-2,x4=2/y4=-2

bonus=bon2+(i-200000)*0.05;,x,y,dl,d2,d3,d4;

elseif(i<=600000)printf(“请输入一个点(x,y):");

bonus=bon4+(i-400000)*0.03;scanf("%f,%f",&x,&y);

elseif(i<=1000000)dl=(x-x4)*(x-x4)+(y-y4)*(y-y4);

bonus=bon6+(i-600000)*0.015;d2=(x-xl)*(x-xl)+(y-yl)*(y-yl);

elsed3=(x-x2)*(x-x2)+(y-y2)*(y-y2);

bonus=bonl0+(i-1000000)*0.01;d4=(x-x3)*(x-x3)+(y-y3)*(y-y3);

printf("奖金是:%10.2f\n”,bonus);if(dl>l&&d2>l&&d3>l&&d4>l)

return0;h=0;

)printf(“该点高度为%d\n",h);

return0;

4-11

)

#include<stdio.h>

5-2

intmain()

(/include<stdio.h>

intt,a,b,c,d;#include<math.h>

printf("请输入四个数:");intmain()

scanf("%d,%d,%d,%cT,&a,&b,&c,&d);{

printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c/intsign=l,count=0;

d);doublepi=0.0,n=1.0/term=1.0;

if(a>b)while(fabs(term)>=le-6)

n=m;

pi=pi+term;m=temp;

n=n+2;)

sign=-sign;p=n*m;

term=sign/n;while(m!=0)

count++;(

)r=n%m;

pi=pi*4;n=m;

printf("pi=%10.8f\n"/pi);m=r;

printf("count=%d\n",count);)

return0;printf(“它们的最大公约数为:%d\n“,n);

)printf("它们的最小公约数

为:%d\n,p/n);

5-2

return0;

#include<stdio.h>}

include<math.h>

5-4

intmain()

(/include<stdio.h>

intsign=l,count=0;intmain()

doublepi=0.0,n=1.0,term=1.0;{

while(fabs(term)>=le-8)charc;

(intletters=0,space=0,digit=0,other=0;

pi=pi+term;printf(“请输入一行字符:\n“);

n=n+2;while((c=getchar())!='\n')

sign=-sign;(

term=sign/n;if(c>='a'&&c<='z'||

count++;c>='A'&&c<二Z)

)letters++;

pi=pi*4;elseif(c==*')

printf("pi=%10.8f\n",pi);space++;

,,

printf("count=%d\n/count);elseif(c>='0'&&c<='9')

return0;digit++;

)else

other++;

5-3

)

include<stdio.h>printf("字母:%d\n空格数:%d\n数字

intmain()数:%d\n其他字符

(数:%d\rT,letters,space,digit,other);

intp,.n,m,temp;return0;

prints请输入两个正整数n,m:");}

scanf(”%d,%d,",&n,&m);

if(n<m);

temp=n;

for(k=l;k<=n3;k++)

5-5

{s3=s3+l/k;}

#include<stdio.h>printf("sum=%15.6f\n"zsl+s2+s3);

intmain()return0;

()

inta,nJ=l,sn=Otn=O;

z5-8

printf("a,n=:");

scanf(”%d,%cT,&a,&n);#include<stdio.h>

while(i<=n)intmain()

({

tn=tn+a;inti,j,k,n;

sn=sn+tn;printf("parcissusnumbersare");

a=a*10;for(n=100;n<1000;n++)

++i;(

)i=n/100;

printf("a+aa+aaa+...=%d\n",sn);j=n/10-i*10;

return0;k=n%10;

)if(n==i*i*i+j*j*j+k*k*k)

printf("%d”,n);

5-6

)

#include<stdio.h>printf("\n");

intmain()return0;

()

doubles=O,t=l;

5-9

intn;

for(n=l;n<=20;n++)include<stdio.h>

(intmain()

t=t*n;{

s=s+t;intm,s,i;

)for(m=2;m<1000;m++)

printf("l!+2!+...+20!=%22.15e\n",s);(

return0;s=0;

)for(i=l;i<m;i++)

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

5-7

if(s==m)

include<stdio.h>{printf("%d,itsfactorsare,m);

intmain()for(i=l;i<m;i++)

(if(m%i==0)printf("%d"J);

int01=100,02=50,n3=10;printf("\n");

doublek,sl=0,s2=0,s3=0;}

for(k=l;k<=nl;k++))

{sl=sl+k;}return0;

for(k=l;k<=n2;k++))

{s2=s2+k*k;}

xl=(x2+l)*2;

5-10

x2=xl;

#include<stdio.h>day-;

intmain()

(printf("total=%d\n",xl);

inti,n=20;return0;

doublea=2,b=l/s=0/t;)

for(i=l;i<=n;i++)

5-16

(

s=s+a/b;include<stdio.h>

t=a,intmain()

a=a+b,|

b=t;intijk;

)for(i=0;i<=3;i++)

printf("sum=%16.10f\n"/s);{for(j=0;j<=2-i;j++)

return0;printf("");

)for(k=0;k<=2*i;k++)

printf("*");

5-11

printf("\n");

include<stdio.h>)

intmain()for(i=0;i<=2;i++)

({

doublesn=100,hn=sn/2;for(j=0;j<=i;j++)

intn;printf("");

for(n=2;n<=10;n++)for(k=0;k<=4-2*i;k++)

(printf("*");

sn=sn+2*hn;printf("\n");

hn=hn/2;}

)return0;

printf("第10次落地时共经过%£米}

\n",sn);

5-17

printf("第10次反弹时%f米\n",hn);

return0;#include<stdio.h>

)intmain()

(

5-12

chari,j,k;

#include<stdio.h>for(i='x';i<=,z';i+4-)

intmain()for(j='x';j<='z';j++)

(if(i!=j)

intday,xl,x2;for(k='x';k<='z,;k++)

day=9;if(i!=k&&j!=k)

x2=l;if(i!='x'&&k!='x'&&kl='z')

while(day>0)printf("A-%c\nB-%c\nC-%c\n"J/j/k),

return0;

inti=0,j=0,a[3][3],sl,s2;

6-1

for(i=0;i<3;i++)

#include<stdio.h>for(j=0;j<3;j++)

intmain()scanf("%d",&a[i][j]);

(sl=a[0][0]+a[l][l]+a[2][2];

inti,j,a[100];s2=a[0][2]+a[l][l]+a[2][0];

for(i=2;i<100;i++)printf("sl=%d,s2=%d\n",sl,s2);

(return0;

a[i]=i;)

for(j=2;j<=i;j++)

6-4

(

if(j<i)#include<stdio.h>

if(a[i]%j==O)intmain()

break;(

if(a[i]-j==O)staticint

printf("%5d",a[i]);a口0]={l,7,8,17,23,24,59,62,101};

)inti,t;

)scanf("%d",&a[9]);

printf("\n");for(i=9;i>0;i-)

return0;if(a[i]<a[i-l])

)(

t=a[i-l];a[i-l]=a[i];a[i]=t;

6-2

)

#include<stdio.h>for(i=0;i<10;i++)

intmain()printf("%5d",a[i]);

(printf("\n");

inti,j,a[10],t;return0;

for(i=0;i<10;i++))

scanf("%d",&a[i]);

6-5

for(j=l;j<10;j++)

for(i=0;i<=9-j;i++)#include<stdio.h>

if(a[i]>a[i+l])intmain()

({

t=a[i+l];a[i+l]=a[i];a[i]=t;int1,6(10];

)for(i=0;i<10;i++)

for(i=0;i<10;i++)scanf("%d"z&b[i]);

printf("%5d\n",a[i]);for(i=9;i>-l;i-)

return0;printf("%5d"zb[i]);

)printf("\n");

return0;

6-3

}

#include<stdio.h>

intmain()

6-6

)

#include<stdio.h>else

intmain()(

(if(i<l)i=n;

staticintmzn,k,b[15][15];if(j>n)j=l;

b[O][l]=l;}

for(m=l;m<15;m++)if(a[i][j]==0)

(a[i][j]=k;

for(n=l;n<=m;n++)else

(

i=i+2;

b[m][n]=b[m-l][n-l]+b[m-l][n];

printf(“%・5d,b[m][n]);a[i][j]=k;

)}

printf("\n");)

)for(i=l;i<=n;i++)

return0;(

}for(j=l;j<=n;j++)

printf("%4d",a[i][j]);

6-7

printf("\n");

#include<stdio.h>)

intmain()return0;

()

inta[16][16],i,j,k,p,n;

6-8

P=l;

while(p==l)#include<stdio.h>

(intmain()

printf("Entern(n=l~15):");(

scanf("%d",&n);inta⑸⑸,b⑸,c⑸,d⑸⑸,k=0,l=0;

if((n!=0)&&(n<=15)&&(n%2!=0))inti,j;

P=0;for(i=0;i<5;i++)

)for(j=0;j<5;j++)

for(i=l;i<=n;i++)scanf("%d",&d[i][j]);

for(j=l;j<=n;j++)a[i][j]=0;for(i=0;i<5;i++)

j=n/2+l;for(j=0;j<5;j++,a[i][j]=d[i][j]);

a⑴for(i=0,k=0;i<5;i++,k++)

for(k=2;k<=n

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论