C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx

上传人:b****3 文档编号:6628759 上传时间:2023-05-07 格式:DOCX 页数:25 大小:20.10KB
下载 相关 举报
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第1页
第1页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第2页
第2页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第3页
第3页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第4页
第4页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第5页
第5页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第6页
第6页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第7页
第7页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第8页
第8页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第9页
第9页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第10页
第10页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第11页
第11页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第12页
第12页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第13页
第13页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第14页
第14页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第15页
第15页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第16页
第16页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第17页
第17页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第18页
第18页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第19页
第19页 / 共25页
C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx_第20页
第20页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx

《C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx(25页珍藏版)》请在冰点文库上搜索。

C程序设计教程与实验第17章习题参考解答Word格式文档下载.docx

61

57

9

112

第3章习题答案:

1

2

3

4

5

6

7

8

10

D

C

A、B

A

B

B、C

1.有穷性确定性可行性

2.#

3.从终端(键盘)输入一个字符

4.md

5.97g

6.123.456000,123.46,123

7.格式控制符不正确(输入数据时不能控制列宽和小数位数)

8.63,63,77,3f

9.%f%f&

x,&

y

10.<

chch

1.c=11

2.a=123f=457

3.x=345

y=3.460000

4.a=1,b=3

a=3,b=1

5.(题目需修改为:

从键盘输入一个除a和z以外的小写字母)

程序的功能:

从键盘输入一个除a和z以外的小写字母,求出该字母对应的大写字母的前趋和后继字母,然后顺序输出此三个大写字母,每个字母所占列宽为3。

运行结果:

假如输入:

f

输出:

EFG

第四章习题答案:

AC

1.!

&

&

||

2.1

3.ab

4.1

5.0

6.x%4==0&

x%100!

=0

7.56

8.A

9.x<

0||x>

10&

x<

50

10.-1

三、编程题

1.

math.h>

{floatx,y;

%f"

&

x);

if(x<

5)y=x*x-2;

elseif(x<

50)y=3*x+5;

elsey=x-sqrt(4*x-1);

x=%f,y=%.3f\n"

x,y);

2.

voidmain()

{floata,b,c,s,area;

%f,%f,%f"

b,&

c);

if(a+b>

c&

b+c>

a&

a+c>

b)

{s=(a+b+c)/2;

area=sqrt(s*(s*(s-a)*(s-b)*(s-c)));

area=%f\n"

area);

if(a==b&

b==c)

等边三角形\n"

elseif(a==b||a==b||b==c)

等腰三角形\n"

elseif((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a))

直角三角形\n"

elseprintf("

一般三角形\n"

}

不能组成三角形\n"

3.

{floatn,r,s;

intm;

请输入奖金值:

"

n);

if(n>

=6000)m=6;

elsem=n/1000;

switch(m)

{case0:

r=0;

break;

case1:

r=0.05;

case2:

r=0.08;

case3:

case4:

case5:

r=0.1;

case6:

r=0.15;

s=n-r*n;

税率r=%.0f%%,奖金值n=%.2f,实际应得奖金值s=%.2f\n"

r*100,n,s);

4.

{inta,b,c,d,t;

%d,%d,%d,%d"

c,&

d);

if(a<

b){t=a;

a=b;

b=t;

c){t=a;

a=c;

c=t;

d){t=a;

a=d;

d=t;

if(b<

c){t=b;

b=c;

d){t=b;

b=d;

if(c<

d){t=c;

c=d;

%d%d%d%d\n"

a,b,c,d);

5.

{intnum,i,j,k,m;

输入一个少于4位的正整数:

%d"

num);

if(num>

=0&

num<

=9999)

{if(num>

1000&

=9999)

{printf("

是一个4位数\n"

m=num%10;

/*求个位上的数字*/

k=num/10%10;

/*求十位上的数字*/

j=num/100%10;

/*求百位上的数字*/

i=num/1000;

/*求千位上的数字*/

逆序数为:

%d%d%d%d\n"

m,k,j,i);

elseif(num>

=100)

是一个3位数\n"

m=num%10;

k=num/10%10;

j=num/100;

printf("

%d%d%d\n"

m,k,j);

=10)

{printf("

是一个2位数\n"

k=num/10;

%d%d\n"

m,k);

else

是一个1位数\n"

%d\n"

num);

是一个无效的数\n"

第5章习题参考答案

A

二填空题

1.循环switch

2.4,7

3.6

4.##

5.02

6.18

7.1

8.sum=80

9.(c=getchar()

n:

m

10.i%13==0

break

三程序分析题

1.output1:

216

output2:

56

output3:

577

2.n=7

3.Max=18

Min=3

4.1*1=1

2*1=22*2=4

3*1=33*2=63*3=9

5.0123

1230

2301

3012

四、编程题

#include"

stdio.h"

main()

{charch;

intk=0;

while((ch=getchar())!

='

\n'

{if(ch=='

A'

||ch=='

a'

k=k+1;

k);

2.

#include<

doubleterm,result=1;

/*累乘项初值应为1*/

intn;

for(n=2;

n<

=100;

n=n+2)

{

term=(double)(n*n)/((n-1)*(n+1));

/*计算累乘项*/

result=result*term;

result=%f\n"

2*result);

3.

#include<

intx,y,z,count=0;

for(x=1;

x<

=28;

x++)

for(y=1;

y<

=73;

y++)

{

z=100-x-y;

if(5*x+2*y+z==150)

{

count++;

printf("

%d,%d,%d\n"

x,y,z);

}

}

count=%d\n"

count);

#include<

{intx,y;

for(x=1;

=97;

{y=98-x;

if(2*x+4*y==386)

鸡=%d,兔=%d"

x,y);

intn,i;

\npleaseinputanumber:

\n"

%d="

n);

for(i=2;

i<

=n;

i++)

while(n!

=i)

if(n%i==0)

%d*"

i);

n=n/i;

elsebreak;

第6章习题参考答案

1.0

2.14m

3.107

4.数据类型

5.strcpy(S2,S1)#include<

string.h>

6.03

7.7,6

8.sum=0

i==j

a[i][j]

9.4

10.Tony

1.max=85

min=5

sum=180

aver=30.00

2.a=2

b=2

c=2

d=2

e=1

f=2

g=2

3.j=45

4.Ti_saCPorm

Tss_Pgm

5.1115

1.从键盘输入15个整数,存放在数组中,找出其中最小数并指出其所在的位置。

#defineN15

{intmin,i,j,a[N];

EnterNintegers:

for(i=0;

N;

scanf("

a[i]);

min=a[0];

for(i=1;

if(min>

a[i])

{min=a[i];

j=i;

%d,%d"

min,j);

2.将输入的十进制正整数化为十六进制数。

inti,x,j,a[20];

请输入一个正整数:

while

(1)

{

0)

数据输入错误,请重新输入一个正整数:

i=0;

while(x)

a[i]=x%16;

x=x/16;

i++;

for(j=i-1;

j>

=0;

j--)

if(a[j]<

=9)

a[j]);

elseif(a[j]<

=15)

%c"

a[j]+'

-10);

3.从键盘输入一行字符,统计其中有多少单词,假设单词之间以逗号分隔。

voidmain()

charstring[81];

inti,num=0,word=0;

charc;

gets(string);

for(i=0;

(c=string[i])!

\0'

;

if(c=='

'

)word=0;

elseif(word==0)

{word=1;

num++;

printf("

Thereare%dwordsintheline.\n"

4.从键盘输入一字符串,放在字符数组a中,将字符数组a中下标值为偶数的元素按从小到大排序。

chara[80],t,m;

inti,j,k;

请输入一字符串:

gets(a);

k=strlen(a);

=k-2;

i+=2)

{m=i;

for(j=i+2;

j<

=k;

j+=2)

if(a[m]>

a[j])

m=j;

if(m!

{t=a[i];

a[i]=a[m];

a[m]=t;

puts(a);

第7章习题参考答案

1.main()

2.main()

3.函数首部

4.解决函数必须“定义在前,使用在后”的原则问题

5.int

6.定义调用

7.地址传递值传递

8.returnvoid

9.voidf(floata,floatb)floatf(floata,floatb)

10.static

1.a=48

2.8,17

3.2721

4.BASIC

C

COBOL

FORTRAN

PASCAL

Smalltalk

5.6

123

654

1.

{intprime(int);

Inputaninteger:

if(prime(n))

\n%disaprime.\n"

else

\n%disnotaprime.\n"

intprime(intn)

{intflag=1,i;

for(i=2;

i<

sqrt(n)&

flag==1;

if(n%i==0)

flag=0;

return(flag);

intMyStrcmp(chars[],chart[]);

charstr1[20],str2[20];

Inputstring:

gets(str1);

Inputanotherstring:

gets(str2);

if(MyStrcmp(str1,str2)>

0)

str1>

str2\n"

elseif(MyStrcmp(str1,str2)<

str1<

str1=str2\n"

intMyStrcmp(chars[],chart[])

inti;

for(i=0;

s[i]==t[i];

i++)

if(s[i]=='

)return0;

return(s[i]-t[i]);

{voidconcatenate(charstring1[],charstring2[],charstring[]);

chars1[100],s2[100],s[100];

inputstring1:

%s"

s1);

inputstring2:

s2);

concatenate(s1,s2,s);

\nThenewstringis%s\n"

s);

voidconcatenate(charstring1[],charstring2[],charstring[])

{inti,j;

string1[i]!

string[i]=string1[i];

for(j=0;

string2[j]!

j++)

string[i+j]=string2[j];

string[i+j]='

#defineARRSIZE10

voidMaxMinExchang(inta[],intn)

intmaxValue=a[0],minValue=a[0],maxPos=0,minPos=0;

inti,temp;

for(i=1;

n;

i++)

if(a[i]>

maxValue)

maxValue=a[i];

maxPos=i;

elseif(a[i]<

minValue)

minValue=a[i];

minPos=i;

temp=a[maxPos];

a[maxPos]=a[minPos];

a[minPos]=temp;

inta[ARRSIZE],i;

Input%dNumbers:

ARRSIZE);

for(i=0;

ARRSIZE;

MaxMinExchang(a,ARRSIZE);

AfterMaxMinExchange:

%4d"

a[i]);

);

#defineN3

intarray[N][N];

{voidconvert(intarray[][3]);

inti,j;

inputarray:

for(j=0;

array[i][j]);

\noriginalarray:

{for(j=0;

%5d"

array[i][j]);

convert(array);

convertarray:

voidconvert(intarray[][3])

{inti,j,t;

for(j=i+1;

{t=array[i][j];

array[i][j]=array[j][i];

array[j][i]=t;

6.

#defineN10

charstr[N];

{voidsort(charstr[]);

inti,flag;

for(flag=1;

flag==1;

{printf("

inputstring:

str);

if(strlen(str)>

N)

stringtoolong,inputagain!

sort(str);

stringsorted:

for(i=0

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

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2