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

下载本文档

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

文档简介

《全国计算机等级考试二级教程一C语言程序设计》课后习题答案

第一章

1.1EXE

1.2COBJEXE

1.3顺序选择循环

第二章

一.选择题

2.1B2.2D2.3B2.4A2.5C2.6A2.7B

2.8B2,9D2.10C2.11B2.12B2.13A

二.填空题

2.141112

2.154.24.2

2.16{}定义执行语句

2.17关键字用户标识符

2.18intfloatdouble

2.19floatal=l;floata2=l;

2.20存储单元

2.213.5

2.22(a*b)/ca*b/ca/c*b

2.23把常量10赋给变量s

2.24位1或0

2.2581270111111-12810000000

2.2632767-327681000000000000000

2.2710816

三.上机改错题

2.28

^include,zstdio.h,z;删除行尾的

main();/*mainfunction*/删除〃)〃后的〃;〃,注释中的*要紧靠即应为"/*”和"*/”

函数开始处遗失了一个“{”

floatr,s;/*/*risradius*/,/*sisareaofcircuilar*/*/注释符号不可嵌套使用

r=5.0;

s=3.14159*r*r;

printfC%f\n",s)行尾遗失了”;”

函数结束处遗失了一个“}“

2.29

#include"stdio.h〃

main/*mainfunction*/main后遗失了"()”

(

floata,b,c,v;/*a,b,caresides,visvolumeofcube*/

a=2.0;b=3.0;c=4.0行尾遗失了“;”

v=a*b*c;

printfC%f\nz/,v)行尾遗失了“

第三章

一.选择题

3.1C3.2C3.3D3.4C3.5D3.6B3.7C3.8D3.9A3.10B

3.11C3.12D3.13D3.14A3.15C3.16C3.17C3.18无答案3.19C3.20B

二.填空题

3.21(1)-2002500(2)i=-200,j=2500

(3)i=-200

j=2500

3.221200

3.23-,条语句;

3.24;

3.25100,25.81,1.8923410025.811.8923410025.811.89234

3.26x=127,x=127,x=177,x=7f,x=127

3.27x=127,x=127,x=$127,x=$000127,x=_d

3.28a=513.789215,a=513.79,a=513.78921500,a=513.78921500

三.编程题和改错题

3.29修改后的程序如下:

main()

(

doublea,b,c,s,v;

printf("inputa,b,c:z,);

scanfC%lf%lf%ir,&a,&b,&c);

s=a*b;

v=a*b*c;

printf(〃a=虹,b=%f,c二%f\n”,a,b,c);

printfCs=%f,v=%f\n,z,s,v);

)

3.30

^include

main()

(

inta=560,b=60;

printf(z,560minuteis%dhourand%dminute.\n\a/b,a%b);

)

3.31

#include

main()

(

inta,b;

a=1500;b=350;

printf(z/adivbis:%d\n”,a/b);

printf(z,amodbis:%d\n",a%b);

)

3.32

#include

main()

doublea,b,c,ave;

printf(,zinput3doublenumber:\n〃);

scanf&a,&b,&c);

printf(〃%.(abc)/3);

)

3.33

#include

voidmain()

(

inta,b,c,t;

printf(〃请依次输入整数a,b,c:〃);

scanf(//%d%d%d,/,&a,&b,&c);

printf("\n你输入的值是:a=%d,b=%d,c=%d\n/z,a,b,c);

t=b;b=a;a=c;c=t;

printf("交换之后的值是:a=%d,b=%d,c=%d\nz/,a,b,c);

)

第四章

一.选择题

4.1A4.2A4.3A4.4D4.5C4.6A4.7B4.8C4.9D4.10C

二.填空题

4.11非00

4.12<>>=<=同级==!=同级

4.13!&&||

4.15!

4.16a==b|a<cx>4||x<-4

4.171

4.18x<=01>0

4.19322

4.20*#

三.编程题

4.21略

4.22

^include

/*检查日期的合法性*/

intcheckdate(intyear,intmonth,intday)

(

if(year<1900|year>2005)

(

printf(〃输入的年份无效!\n");

return0;

)

elseif(month<0&&month>12)

(

printf(〃输入的月份无效!\n〃);

return0;

elseif(day<=0&&day>31)

(

printf("输入的日期无效!\n〃);

return0;

)

else

(

switch(month)

(

case4:

case6:

case9:

case11:

if(day>30)

(

printf("输入的日期无效!\n");

return0;

)

break;

case2:

if((year%4==0&&year_0!=0)year©0==0)

(

if(day>29)

(

printf(〃输入的日期无效!\n");

return0;

)

)

else

{

if(day>28)

(

printf(〃输入的出生日期无效!\n〃);

return0;

)

)

break;

}/*endofswitch(m0)*/

)

return1;

voidmain()

(

intyO,mO,dO;/*生日*/

intyl,ml,dl;/*当前日期*/

intyears,months,days;/*实足年龄*/

printf(〃请输入学生的生日:〃);

scanf("%d%d%d”,&yO,&mO,&dO);

if(checkdate(yO,mO,dO))

(

printf(〃请输入当前日期:〃);

scanf(,,%d%d%dz,,&yl,&ml,&dl);

/*当前日期合法性检查*/

if(!checkdate(yl,ml,dl))

(

return;

)

elseif(yO>yl)

(

printf("出生年份比当前年份晚!\n");

return;

)

elseif(yO==yl)

(

if(mO>ml)

(

printf("出生年月比当前年月晚!\n");

return;

}

elseif(mO==ml)

(

if(dO>dl)

(

printf("出生年月日比当前年月日晚!\n");

return;

)

)

)

)

/*计算实足年龄*/

years=yl-yO;

months=ml-mO;

days=dl-dO;

/*修正实足年龄天数*/

if(days<0)

(

months一;

switch(ml)

(

case1:

case5:

case7:

case10:

case12:

days=30;

break;

case2:

case4:

case6:

case8:

case9:

case11:

days=31;

break;

case3:

if((yl%4==0&&yl_0!=0)||yl@0==0)

(

days=29;

)

else

(

days=28;

)

break;

}/*endofswitch(ml)*/

}/*endofif(days<0)*/

/*修正实足年龄月数*/

if(months<0)

(

months=12;

years——;

}/*endofif(months<0)*/

printf(〃出生日期:%d年%d月%(1日\11”,y0,m0,dO);

printf(〃当前日期:%d年%d月%d日\n”,yl,ml,dl);

printf(〃实足年龄:%d年%d月%(1日\11",years,months,days);

return;

)

4.23

#include

voidmain()

(

inta;

printf("请输入一个整数:");

scanf(〃%d〃,&a);

if(a%2==0)

printf("%d是偶数\n",a);

)

else

(

printf(*%d是奇数\n”,a);

)

)

4.24

ttinclude

voidmainO

(

inta,b,c,temp,max;

printf("请输入三个整数

scanf(线d%d%d”,&a,&b,&c);

temp=(a>b)?a:b;

(nax=(temp>c)?temp:c;

printf;

printf("你输入的数中最大的是%d.\n",max);

)

4.25

(1)不嵌套的if语句

Sinclude

voidraain()

(

intx,y;

printf("inputx;

scanf&x);

if(x>-5&&x<0)

(

printf(,zyis%d\n”,y=x);

)

if(x==0)

(

printf("yis%d\n”,y=xT);

)

if(x>0&&x<10)

(

printfCyis%d\n”,y=x1);

}

if(x>=10||x<=-5)

(

printf("error'n");

)

)

(2)嵌套的if语句

^include

voidmain()

(

intx,y;

printf("inputx:")

scanf&x);

printf("\n");

if(x<0)

(

if(x>-5)

(

printf("yis%d.\n,y=x);

)

else

(

printf("error!\n");

)

)

if(0==x)

(

printf("yis%d.\n,y=x-l);

}

if(x>0)

(

if(x<10)

(

printf(/?yis%d.\n,y=x1);

}

else

(

printf("error!\n");

)

)

)

(3)if_el,se语句

ttinclude

voidmain()

(

intx,y;

printf(*inputx:")

scanf&x);

if(x>-5&&x<0)

(

printf("yis%d.\n',y=x);

elseif(x==0)

printfCyis%d.\n〃,y=x-l);

)

elseif(x>0&&x<10)

(

printf(z/yis%d.\n〃,y=x1);

)

else

(

printf(""error!\nz,);

)

)

(4)switch语句

#include

voidmain()

(

intx,y;

printf("inputx:;

scanf&x);

switch(x)

(

case-4:

case-3:

case-2:

case-1:

printf(,zyis%d.\n〃,y=x);

break;

case0:

printffyis%d.\n",y=x-l);

break;

case1:

case2:

case3:

case4:

case5:

case6:

case7:

case8:

case9:

printf(z/yis%d.\n〃,y=x1);

break;

default:

printf("error!\n〃);

)

)

第五章

一.选择题

5.1D5.2C5.3B5.4C5.5C5.6B5.7D5.8A5.9D5.10D

二.填空题

5.11546

5.12死循环

5.13-1

5.1411

5.15d=1.0kk<=n

5.16x>=0x

三.编程题

5.17

#include

voidmain()

(

inti;

intsig=1;

intsum=0;

for(i=l;i<=101;i,i)

(

sum=sig*i;

sig*=-1;

)

printf("sum二%d\n〃,sum);

)

5.18

(1)

#include

voidmain()

(

inti;

doublem=l.0;

doublee=1.0;

for(i=l;i<50;i)

(

m*二i;

e=1/m;

)

printf(〃e=%f\n〃,e);

)

(2)

#include

voidmain()

(

inti=l;

doublem=l.0;

doublee=1.0;

while(1/m>=0.0004)

(

m*二i;

e=1/m;

i;

)

printfe);

)

5.19

#include

voidmain()

(

intyear;

intcol=0;

for(year=1600;year<=:2000;year)

(

if((year%4==0&&year_0!=0)year^O==0)

(

printf(〃%d\t〃,year);

col;

if(col%5==0)

(

printf(〃\n〃);

)

)

)

printf(〃\n");

)

5.20

#include

#defineN7

voidmain()

(

inti;

intj;

intm;

intk=N/2;

for(i=0;i{

m=i-k;

if(m<0)

m*=-1;

for(j=0;j{

printfC〃);

)

for(j=0;j<2*(k-m)1;j)

(

printf(〃*〃);

)

printf(〃\n〃);

)

第六章

一.选择题

6.1B6.2D6.3A6.4A6.5B6.6D6.7D6.8B6.9A6.10A6.11C

二.填空题

6.12-1

6.131

6.14ctype.h

6.151

6.1610A20B30C40D

6.177.29101.298AB

6.18A7.29B101.298

6.19ABC(每个字符后有三个空格)

三.编程题

6.20

#include

ttdefineN80

voidmain()

(

charstr[N];

intiLoop=0;

gets(str);

while(str[iLoop])

(

printf(z/%c-%d\tz,,str[iLoop],str[iLoop]);

iLoop;

if(iLoop%3==0)

(

printf(〃\n〃);

)

)

printf(〃\n〃);

6.21

#include

#defineN80

voidmain()

(

charstr[N];

intnum=0;

intiLoop=0;

gets(str);

while(str[iLoop])

(

if(str[iLoop]〉='O'&&str[iLoop]<='9')

(

num=10*num(str[iLoop]-'0');

)

iLoop;

)

printf(〃%d\n〃,num);

)

6.22

#include

#include

#defineN80

voidmain()

(

charstr[N];

intnum=-1;

do

(

gets(str);

num;

}while(strcmp(str,"EOF"));

printf("您输入了刎行字符!\nz,,num);

)

6.23

#include

#defineN80

voidmain()

(

charstr[N];

intiLoop=0;

intnum=0;

gets(str);

while(str[iLoop]&&iLoop<N)

if(str[iLoop]>='a'&&str[iLoop]<='z')

(

num;

)

iLoop;

)

printf("您输入了字符中有刎个小写字母!\n”,num);

)

6.24

ttinclude

voidmain()

(

int1ine;

intiLoopl;

intiLoop2;

printf(〃请输入图案的行数(不大于26):〃);

scanf&line);

for(iLoopl=0;iLoopl<line;iLoopl)

(

for(iLoop2=0;iLoop2<line-iLoopl;iLoop2)

(

printfC3;

)

for(iLoop2=0;iLoop2<2*iLoopl1;iLoop2)

(

printfiLoopl,A,);

)

printfC\n/Z);

)

)

第七章

一.选择题

7.1C7.2C7.3B7.4C7.5A7.6D7.7A

二.填空题

7.812

7.99.000000

7.104

7.11n=ls

7.12<=yz*x

7.131s*i0f(k)

三.程序调试和编程题

7.14

fun(intn)

{intk,yes;

for(k=2;k<=n/2;k)

(

if(n%k==0){yes=0;break;}

elseyes=1;

)

returnyes;

)

7.15

intmymod(inta,intb)

(

returna%b;

)

7.16

doublefun(intn)

(

doublesum=0;

intiLoop;

intsig=-1;

for(iLoop=l;iLoop<=n;iLoop)

(

sig*=-1;

sum=sig*l.0/iLoop;

)

returnsum;

)

7.17

doublefun(intn)

{

doublet=1.0;

intiLoop;

longtmp;

for(iLoop=2;iLoop<=n;iLoop)

(

tmp=iLoop*iLoop;

t-=1.0/tmp;

)

returnt;

)

7.18

^include

^include

doublefun(doublex)

returnx*x5*x4;

voidmain()

(

intx=2;

printfCyl=%f\n",fun(x));

printf(//y2=%f\n,\fun(x15));

printf(,,y3=%f\n,/,fun(sin(x)));

)

2005-7-2917:53myhomel702

第八章

一.选择题

8.1A8.2B8.3B8.4C8.5B8.6B8.7C8.8D8.9B8.10C8.11C8.12C

二.填空题

8.13110

8.1471

8.15(l)char*p=&ch;(2)p=&ch;(3)scanf(,z%cz/,p);(4)*p=,A,;(5)printf(,z%c,z,*p);

8.16(l)s=p3;(2)s=s-2(3)50(4)*(s1)(5)2(6)1020304050

三.编程题

8.17

voidfun(doublex,doubley,double*sum,double东div)

(

*sum=xy;

*div=x-y;

return;

)

8.18

voidfun(doublex,doubley,doublez,double*max,double*min)

(

*max=x;

*min=x;

if(*max<y)

(

*max=y;

)

if(*max<z)

(

*max=z;

)

if(*min>y)

(

*min=y;

)

if(*min>z)

(

*min=z;

return;

第九章

一.选择题

9.1D9.2A9.3A9.4C9.5C9.6A9.7B9.8D9.9C9.10C

9.11C9.12D9.13D9.14A9.15A9.16A9.17C9.18C

二.填空题

9.1990

9.206

9.2112

9.223

9.232721

9.24-850,2,0

9.25k=pk

9.26(c=getchar())c-'A'

三.编程题

9.27

#include

^defineN81

intmain()

(

intcounter[10]={0};

intiLoop=0;

charstr[N];

gets(str);

while(str[iLoop])

(

if(str[iLoop]>='O'&&str[iLoop]<='9')

(

counter[str[iLoop]-'O'];

)

iLoop;

)

for(iLoop=0;iLoop<10;iLoop)

(

printf(z,%d-%d\n〃,iLoop,counter[iLoop]);

)

return0;

)

9.28

voidfun(intarray[],intarraysize,intstart)

(

intiLoop;

if(start<arraysize-1)

if(start<=0)

start=1;

)

for(iLoop=start;iLoop<arraysize;iLoop)

(

array[iLoop_1]=array[iLoop];

)

)

for(iLoop=0;iLoop<arraysize;iLoop)

(

printf(〃No.%d=%d\n〃,iLoop,array[iLoop]);

)

)

9.29

intfun(intarryl[],intarry2[],intarrysize)

(

intiLoop;

intcounter=0;

for(iLoop=0;iLoop<arrysize;iLoop)

(

if(arryl[iLoop]%2)

(

arry2[counter]=arryl[iLoop];

)

)

returncounter;

)

9.30

voidfun(chararray[],intarraysize)

(

intiLoopl;

intiLoop2;

chartemp;

/*冒泡排序*/

for(iLoopl=0;iLoopl<arraysize-1;iLoopl)

{

for(iLoop2=0;iLoop2<arraysize-1-iLoopl;iLoop2)

(

if(array[iLoop2]<array[iLoop21])

(

temp=array[iLoop2];

array[iLoop2]=array[iLoop21];

array[iLoop21]二temp;

)

)

)

)

9.31

^include

voidfun(intarray[],intarraysize,intinertNumber)

(

intiLoop;

intiLoop2;

if(array[0]<array[arraysize-1])

(

for(iLoop=0;iLoop<arraysize;iLoop)

(

if(array[iLoop]>inertNumber)

(

for(iLoop2=arraysize-1;iLoop2>=iLoop;iLoop2一)

(

array[iLoop21]=array[iLoop2];

)

array[iLoop]=inertNumber;

break;

)

)

if(iLoop>=arraysize)

(

array[arraysize]=inertNumber;

)

)

else

(

for(iLoop=0;iLoop<arraysize;iLoop)

(

if(array[ILoop]<inertNumber)

(

for(iLoop2=arraysize-1;iLoop2>=iLoop;iLoop2一)

(

array[iLoop21]=array[iLoop2];

)

array[iLoop]=inertNumber;

break;

)

)

if(iLoop>=arraysize)

(

array[arraysize]=inertNumber;

)

)

)

intmain()

(

intiLoop;

inta[20]={7,6,5,3,2,1};

for(iLoop=0;iLoop<6;iLoop)

printf(,z%d”,a[iLoop]);

)

printfr\nz/);

fun(a,6,0);

for(iLoop=0;iLoop<7;iLoop)

(

printf(,z%da[iLoop]);

)

printf(〃\n〃);

fun(a,7,4);

for(iLoop=0;iLoop<8;iLoop)

(

printf(z/%d”,a[iLoop]);

)

printf(z,\nz/);

fun(a,8,8);

for(iLoop=0;iLoop<9;iLoop)

(

printf(绘d”,a[iLoop]);

)

printf(〃\n〃);

return0;

)

9.32

intfun(intnumber,intarray[])

(

intiLoop=0;

intiLoop2;

intbinLen;

intmidNumber;

intdiv;

intremain;

midNumber二number;

do

(

div=midNumber/2;

remain=midNumber%2;

midNumber=div;

array[iLoop]=remain;

}while(midNumber);

binLen=iLoop;

for(iLoop2=0,iLoop=binLen-1;iLoop2<iLoop;iLoop2,iLoop一)

midNumber=array[iLoop2];

array[iLoop2]=array[iLoop];

array[iLoop]=midNumber;

)

returnbinLen;

)

9.33

#include

#include

#defineN15

voidfun(intarray[],intarraysize)

(

intx;

intiLoop;

intiLoop2;

for(iLoop=0;iLoop<arraysize;iLoop)

(

iLoop2=0;

x=rand();

do

(

if(x==array[iLoop2]&&iLoop>0)

(

x=rand();

iLoop2=0;

)

iLoop2;

}while(iLoop2<iLoop);

array[iLoop]=x;

)

)

intmainO

(

inta[N];

intiLoop;

fun(a,N);

for(iLoop=0;iLoop<N;iLoop)

(

printf("%d\n〃,a[iLoop]);

)

return0;

第十章

一.选择题

10.1C10.2B10.3C10.4B10.5C10.6A10.7C10.8A10.9C10.10C

二.填空题

10.11GFEDCB

10.12XYZ

10.13SO

10.1410

10.15Itis

10.16strlen(str)-lj一

10.173

10.18goodgood!

三.编程题

10.19

char*mygets(char*str)

(

intiLoop=0;

charch;

while((ch=getchar())!=>\n)

(

str[iLoop]=ch;

)

str[iLoop]='\0';

returnstr;

)

char*myputs(char*str)

(

intiLoop=0;

while(str[iLoop])

{

putchar(str[iLoop]);

)

putchar('\n);

returnstr;

)

10.20

#include

^include

intfun(char*str)

(

intlen;

intiLoopl;

intiLoop2;

intresult=1;

len=strlen(str);

for(iLoopl=0,iLoop2=len-1;iLoopl<iLoop2;iLoopl,iLoop2一)

if(str[iLoopl]!=str[iLoop2])

(

result=0;

break;

)

)

returnresult;

)

intmain()

(

chara[20]=〃ABCDCBA〃;

charb[20]=〃ABCDEBA〃;

printf(〃%d\n〃,fun(a));

printf(z,%d\n,z,fun(b));

return0;

)

10.21

charfun(char*str,intpos)

(

int1en;

intiLoop;

charch;

len=strlen(str);

if(pos>len)

{

returnNULL;

)

ch=str[pos];

for(iLoop=pos;iLoop<len-1;iLoop)

(

str[iLoop]=str[iLoop1];

)

str[len-1]二'\0';

returnch;

)

2005-7-2917:54myhomel702

第十一章

一.选择题

11.1D11.2B11.3A11.4C

二.填空题

11.5IJKLEFGHABCD

11.67

11.78

11.8*(sj)i1i

11.917

11.10(*fun)()(*fun)(ai*h)/hmypoly

三.编程题

11.11

#include

^include

ttdefineN81

intmain(intargc,char**argv)

(

charsig;

intdig;

intpos;

charstr[N]={'\0'};

charoutStr[N]={'\0'};

if(argc<2)

(

.>,

sig=~;

dig=10;

)

else

(

sig=argv[l][0];

dig=argv[l][l]-'O';

)

printf(〃请输入一个字符串:〃);

gets(str);

if(sig==,」)

(

pos=strlen(str)-dig;

if(pos<=0)

(

pos=0;

)

strcpy(outStr,strpos);

)

elseif(sig='')

(

strcpy(outStr,str);

pos=strlen(outStr);

if(pos>dig)

(

pos=dig;

)

outStr[pos]='\0';

printf(〃处理后的字串为:〃);

printf(z,%s\nz,,outStr);

return0;

)

11.12

^include

#include

voidmovebin(char*bin)

(

int1en;

intiLoop;

len=strlen(bin);

for(iLoop=len;iLoop>0;iLoop一)

(

bin[iLoop]=bin[iLoop-1];

)

return;

)

voidfun(intn,char*bin)

(

intpos;

pos=strlen(bin);

if(n==0)

(

return;

)

if(n==1)

(

movebin(bin);

bin[0]='1';

return;

)

movebin(bin);

bin[0]=(n%2)'O';

n/=2;

fun(n,bin);

return;

)

intmain()

(

inta=4;

charbin[50]={〃"};

fun(a,bin);

printf(〃%s\n〃,bin);

return0;

)

11.13

#include

longfun(intn)

(

if(n==1)

(

returnn;

)

else

(

returnfun(n-l)n;

)

)

intmain()

(

intnum;

intsum;

printf("请输入一个自然数:");

scanf(〃%d”,&num);

sum=fun(num);

printf("结果是:%d\nz,,sum);

return0;

}

11.14

#include

intfun(intn)

(

if(n==0||n==1)

(

return1;

)

else

(

returnfun(n-1)fun(n-2);

)

intmain()

intnum;

intresult;

printf("请输入一个自然数:");

scanf(〃%d〃,&num);

result=fun(num);

printf(〃斐波拉契级数为:%d\n/z,result);

return0;

第十二章

一.选择题

12.1B12.2B12.3A12.4C12.5D12.6B12.7A12.8A

二.填空题

12.92,5,1,2,3,-2

12.102468

第十三章

一.选择题

13.1A13.2C13.3B13.4C13.5D13.6D13.7D

二.填空题

13.8ar=9ar=9ar=ll

13.9int*s*b

三.编程题

13.10

#defineMYALPIIA(C)((C〉='A'&&C<=1:)||(C>='a'&&C〈='z'))?1:0

13.11

^defineSWAP(t,x,y){ttmp;tmp=x;x=y;y=tmp;}

13.12

Sinclude

#include

intmain()

(

int*p;

inttmp;

intiLoop;

intiLoop2;

p二(int*)malloc(sizeof(int)*3);

scanf(〃%d%d%d〃,p,p1,p2);

for(iLoop=0;iLoop<2;iLoop)

for(iLoop2=0;iLoop2<2-iLoop;iLoop2)

(

if(*(piLoop2)>*(piLoop21))

(

tmp=*(piLoop2);

*(piLoop2)=*(piLoop21);

*(piLoop21)=tmp;

)

)

)

printf(/z%d%d%d\n,z,*p,*(p1),*(p2));

free(p);

p=NULL;

return0;

第十四章

一.选择题

14.1D14.2D14.3D14.4A14.5C14.6C14.7C14.8B

二.填空题

14.9structlink*next

14.10p->nextm>p->data

14.11(structlist*)structliststructlist*structlistreturnh

三.编程题

14.12

#include

#defineN3

structstud

(

charnum[5],name[10];

ints[4];

doubleave;

);

voidreadrec(structstudarray[],intsize)

(

intiLoop;

for(iLoop=0;iLoop{

scanf(〃%s%s%d%d%d%d〃,array[iLoop].num,array[iLoop].name,

&array[iLoop].s[0],&array[iLoop].s[l],

&array[iLoop].s[2],&array[iLoop].s[3]);

array[iLoop].ave=(array[iLoop].s[0]array[iLoop].s[l]

array[iLoop].s[2]array[iLoop].s[3])/4.0;

return;

voidwriterec(structstudarray[],intsize)

(

intiLoop;

for(iLoop=0;iLoop{

printf(/,%s\t%s\t%d\t%d\t%d\t%d\t%f\n/,,

array[iLoop],num,array[iLoop].name,array[iLoop],s[0],

array[iLoop].s[l],array[iLoop].s[2],array[iLoop].s[3],

array[iLoop],ave);

)

return;

intmain()

structstudstu[N];

readrec(stu,N);

writerec(stu,N);

return0;

14.13

#include

ttinclude

ttdefineN100

structnode

(

intdata;

structnode*next;

);

intseekMaxValue(structnode*pNodc)

(

intmax;

structnode*pMove;

pMove=pNode;

max=pMove->data;

pMove=pMove->next;

while(pMove)

if(max<pMove->data)

max=pMove->data;

)

pMove=pMove->next;

)

returnmax;

)

structnode*seekMaxValueAddress(structnode*pNode)

(

intmax;

structnode*maxAddress;

structnode*pMove;

pMove=pNode;

max=pMove->data;

maxAddress=pMove;

pMove=pMove->next;

while(pMove)

(

if(max<pMove->data)

(

max=pMove-〉data;

maxAddress=pMove;

)

pMove=pMove->next;

}

returnmaxAddress;

)

intmain()

(

structnode*head;

structnode*pNode;

intiLoop;

head=(structnode*)mallo

温馨提示

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

评论

0/150

提交评论