C语言课后实验教程习题答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第五章答案

-1-

1. 【答案】:

(1) m=1 n=2

(2) m=2 n=3

(3) a>0 并且a

2. 【答案】:

(2)for (i=0;i<10;i++) {……}

3. 【答案】:32

4. 【答案】:

main()

{

char x ;

int y;

printf("please input :");

scanf("%c",&x);

if(x>=0 && x<=31)

printf("%c is controll char.",x);

else if(x>=48 && x<=57)

printf("%c is number.",x);

else if(x>='a' && x<='z')

printf("%c is min letter.",x);

else if(x>='A' && x<='Z')

printf("%c is max letter.",x);

else if((x>=8 &&

x<=13)||(x=92)||(x=39)||(x=34))

printf("%c is transferred meaning char:"); else

printf("%c is other char.") ;

}

5. 【答案】:

main()

{

float x;

printf("please input x:");

scanf("%f",&x);

if(x>10)

x=x*x+0.5;

else if(x>0 && x<=10)

x=x*x*x-1;

-2-

else if(x<=0)

x=x*x+4*x; printf("%f",x);

}

6. 【答案】:

#include

main( )

{

double m,i=0.0;

int t;

printf("输入存入的本金:");

scanf("%lf",&m);

printf("\n 输入存钱的期限(整年数):"); scanf("%d",&t);

switch(t)

{

case 1:i=m*0.00225;break;

case 2:i=m*0.00276;break;

case 3:i=m*0.00316;break;

case 4:i=m*0.00395;break;

case 5:i=m*0.00470;break;

}

printf("到期时的利息为%lf,利息与本金的合计为%lf",i,m+i);

}

7. 【答案】:

main()

{

int x;

int z,z1,z2;

printf("please input a number x(0=

if(x>=100)

{

z1=x/100;

x=x-z1*100;

z2=x/10;

x=x-z2*10;

-3-

z=z1+z2+x;

}

else if(x>=10)

{

z1=x/10;

x=x-z1*10;

z=z1+x;

}

else

z=x;

printf("%d",z);

}

8. 【答案】

#include

main()

{

char c;

char s;

printf("\nprintf input a letter:");

/*scanf("%c",&c); */

c=getchar();

if (c=='m'||c=='M')

printf("%c replace Monday.",c);

if(c=='t'||c=='T')

{

printf("\nplease input next letter:"); getchar();

s=getchar();

if(s=='u'||s=='U')

printf("%c%c replace Tuesday,",c,s); else

if(s=='h'||s=='H')

printf("%c%c replace Thursday.",c,s); else

printf("%c not replace.",c);

}

-4-

if(c=='w'||c=='W')

printf("%c replace Wednesday.",c); if(c=='f'||c=='F')

printf("%c replace Friday.",c);

if(c=='s'||c=='S')

{

printf("please input next letter:"); getchar();

s=getchar();

if(s=='a'||s=='A')

printf("%c%c is Saturday.",c,s);

else

if(s=='u'||s=='U')

printf("is sunday."); else

printf("err");

}

}

9. 【答案】:

main()

{

int year;

int month;

printf("please input year:");

scanf("%d",&year);

printf("please input month:");

scanf("%d",&month);

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: printf("%d year %d month have 31 days.",year,month);break;

case 4:

case 6:

-5-

case 9:

case 11:printf("%d year %d month have 30 days.",year,month);break;

}

if((year%4==0 &&

year%100==0)||(year%400==0)&&(month==2))

printf("%d year %d month have 29 days.",year,month); else if(month==2)

printf("%d year %d month have 28 days.",year,month) ; }

10. 【答案】:

include

main()

{

int i,m=1,n=2,k,t,sum=0;

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

{

k=n/m;

相关文档
最新文档