《C语言程序设计》第8章习题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1、选择题
(1)A(2)D(3)B(4)A(5)D(6)B(7)B(8)C(9)B(10)B(11)C 2、填空题
(1)#include
(2)#define
(3)3 5 5
(4)a=4,b=13
a=13,b=4
(5)10
(6)16
(7)1000 10
(8)10
(9)the max value is 2
(10)2
3、程序设计题
(1)
#define LETTER 1
main()
{ int i;
char c;
char str[80];
printf("Please enter a string:");
scanf("%s",str);
i=0;
while((c=str[i])!='\0')
{
i++;
#ifdef LETTER
if(c>='a'&&c<='z')
c=c-32;
#else
if(c>='A'&&c<='Z')
c=c+32;
#endif
printf("%c",c);
printf("%d",(int)c);
}
}
(2)
#include
#include "d:188011.c"
#include "d:188012.c"
#include "d:188013.c"
int fmax(int x,int y,int z);
int fmin(int x,int y,int z);
int faver(int x,int y,int z);
main()
{
int a,b,c;
int max=0;
int min=0;
int average=0;
printf("Please enter three number:");
scanf("%d,%d,%d",&a,&b,&c);
max=fmax(a,b,c);
min=fmin(a,b,c);
average=faver(a,b,c);
printf("The max of the three number is: %d.\n",max);
printf("The min of the three number is: %d.\n",min);
printf("The average of the three number is %d.\n",average); }
/*188011.c*/
int fmax(int x,int y,int z)
{ int max;
max=x;
if(x if(max return(max); } /*188012.c*/ int fmin(int x,int y,int z) { int min=x; if(min>y) {min=y; if(min>z) min=z; } else return min; } /*188013.c*/ int faver(int x,int y,int z) { int aver=0; aver=(x+y+z)/3; return aver; }