首页 > 试题

二级c语言程序设计

更新时间:2023-01-30 07:50:53 阅读: 评论:0

初三数学抛物线试题-半斤八两什么意思


2023年1月30日发(作者:侵犯商标权)

《全国计算机等级考试二级教程--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.19floata1=1;floata2=1;

2.20存储单元

2.21

3.5

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

2.23把常量10赋给变量s

2.24位1或0

2.2581270111111-

2.2632767-327680

2.2710816

三.上机改错题

2.28

#include"stdio.h";删除行尾的";"

main();/*mainfunction*/删除")"后的";",注释中的*要紧靠“/”,

即应为“/*”和“*/”

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

floatr,s;/*/*risradius*/,/*sisareaofcircuilar*/*/注释符

号不可嵌套使用

r=5.0;

s=3.14159*r*r;

printf("%fn",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行尾遗失了“;”

printf("%fn",v)行尾遗失了“;”

}

第三章

一.选择题

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

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

3.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=%06d

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:");

scanf("%lf%lf%lf",&a,&b,&c);

s=a*b;

v=a*b*c;

printf("a=%f,b=%f,c=%fn",a,b,c);

printf("s=%f,v=%fn",s,v);

}

3.30

#include

main()

{

inta=560,b=60;

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

}

3.31

#include

main()

{

a=1500;b=350;

printf("adivbis:%dn",a/b);

printf("amodbis:%dn",a%b);

}

3.32

#include

main()

{

doublea,b,c,ave;

printf("input3doublenumber:n");

scanf("%lf%lf%lf",&a,&b,&c);

printf("%.1fn",(a+b+c)/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=%dn",a,b,c);

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

printf("交换之后的值是:a=%d,b=%d,c=%dn",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||a4||x<-4

4.171

4.18x<=01>0

4.19322

4.20*

#三.编程题

4.21略

4.22

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

intcheckdate(intyear,intmonth,intday)

{

if(year<1900||year>2005)

{

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

return0;

}

elif(month<0&&month>12)

{

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

return0;

}

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

{

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

return0;

}

el

{

switch(month)

{

ca4:

ca6:

ca9:

ca11:

if(day>30)

{

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

return0;

}

break;

ca2:

if((year%4==0&&year%100!=0)||year%400==0){

if(day>29)

{

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

return0;

}

}

el

{

if(day>28)

{

printf("输入的出生日期无效!n");return0;

}

}

break;

}/*endofswitch(m0)*/

}

return1;

}

voidmain()

{

inty0,m0,d0;/*生日*/

inty1,m1,d1;/*当前日期*/

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

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

scanf("%d%d%d",&y0,&m0,&d0);

if(checkdate(y0,m0,d0))

{

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

scanf("%d%d%d",&y1,&m1,&d1);

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

if(!checkdate(y1,m1,d1))

{

return;

}

elif(y0>y1)

{

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

}

elif(y0==y1)

{

if(m0>m1)

{

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

}

elif(m0==m1)

if(d0>d1)

{

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

return;

}

}

}

}

/*计算实足年龄*/

years=y1-y0;

months=m1-m0;

days=d1-d0;

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

if(days<0)

{

months--;

switch(m1)

{

ca1:

ca5:

ca7:

ca10:

ca12:

days+=30;

break;

ca2:

ca4:

ca6:

ca8:

ca9:

ca11:

days+=31;

break;

ca3:

if((y1%4==0&&y1%100!=0)||y1%400==0){

days+=29;

}

el

{

days+=28;

break;

}/*endofswitch(m1)*/

}/*endofif(days<0)*/

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

if(months<0)

{

months+=12;

years--;

}/*endofif(months<0)*/

printf("出生日期:%d年%d月%d日n",y0,m0,d0);

printf("当前日期:%d年%d月%d日n",y1,m1,d1);

printf("实足年龄:%d年%d月%d日n",years,months,days);

return;

}

4.23

#include

voidmain()

{

inta;

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

scanf("%d",&a);

if(a%2==0)

{

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

}

el

{

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

}

}

4.24

#include

voidmain()

{

inta,b,c,temp,max;

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

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

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

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

printf("n");

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

4.25

(1)不嵌套的if语句

#include

voidmain()

{

intx,y;

printf("inputx:");

scanf("%d",&x);

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

{

printf("yis%dn",y=x);

}

if(x==0)

{

printf("yis%dn",y=x-1);

}

if(x>0&&x<10)

{

printf("yis%dn",y=x+1);

}

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

{

printf("errorn");

}

}

(2)嵌套的if语句

#include

voidmain()

{

intx,y;

printf("inputx:");

scanf("%d",&x);

printf("n");

if(x<0)

{

if(x>-5)

{

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

el

{

printf("error!n");

}

}

if(0==x)

{

printf("yis%d.n",y=x-1);}

if(x>0)

{

if(x<10)

{

printf("yis%d.n",y=x+1);}

el

{

printf("error!n");

}

}

}

(3)if_el语句

#include

voidmain()

{

intx,y;

printf("inputx:");

scanf("%d",&x);

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

{

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

elif(x==0)

{

printf("yis%d.n",y=x-1);}

elif(x>0&&x<10){

printf("yis%d.n",y=x+1);}

el

{

printf("error!n");

}

}

(4)switch语句

#include

voidmain()

{

intx,y;

printf("inputx:");

scanf("%d",&x);

switch(x)

{

ca-4:

ca-3:

ca-2:

ca-1:

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

ca0:

printf("yis%d.n",y=x-1);break;

ca1:

ca2:

ca3:

ca4:

ca5:

ca6:

ca7:

ca8:

ca9:

printf("yis%d.n",y=x+1);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.0k++k<=n

5.16x>=0x

三.编程题

5.17

#include

voidmain()

{

inti;

intsig=1;

intsum=0;

for(i=1;i<=101;i++,i++)

{

sum+=sig*i;

sig*=-1;

}

printf("sum=%dn",sum);

}

5.18

(1)

#include

voidmain()

{

inti;

doublem=1.0;

doublee=1.0;

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

{

m*=i;

e+=1/m;

}

printf("e=%fn",e);

}

(2)

#include

voidmain()

{

inti=1;

doublem=1.0;

doublee=1.0;

while(1/m>=0.0004)

{

m*=i;

e+=1/m;

i++;

}

printf("e=%fn",e);

}

5.19

#include

voidmain()

{

intyear;

intcol=0;

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

{

if((year%4==0&&year%100!=0)||year%400==0){

printf("%dt",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{

printf("");

}

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.17

7.29101.298AB

6.18A

7.29B101.298

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

三.编程题

6.20

#include

#defineN80

voidmain()

{

intiLoop=0;

gets(str);

while(str[iLoop])

{

printf("%c-%dt",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]>='0'&&str[iLoop]<='9'){

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

}

iLoop++;

}

printf("%dn",num);

}

6.22

#include

#include

#defineN80

voidmain()

{

charstr[N];

do

{

gets(str);

num++;

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

printf("您输入了%d行字符!n",num);

}

6.23

#include

#defineN80

voidmain()

{

charstr[N];

intiLoop=0;

intnum=0;

gets(str);

while(str[iLoop]&&iLoop

{

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

{

num++;

}

iLoop++;

}

printf("您输入了字符中有%d个小写字母!n",num);}

6.24

#include

voidmain()

{

intline;

intiLoop1;

intiLoop2;

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

scanf("%d",&line);

for(iLoop1=0;iLoop1

{

for(iLoop2=0;iLoop2

{

printf("");

}

for(iLoop2=0;iLoop2<2*iLoop1+1;iLoop2++){

printf("%c",iLoop1+'A');

}

printf("n");

}

}

第七章

一.选择题

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

二.填空题

7.812

7.99.000000

7.104

7.11n=1s

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;}

elyes=1;

}

returnyes;

}

7.15

intmymod(inta,intb)

{

returna%b;

}

7.16

doublefun(intn)

{

doublesum=0;

intiLoop;

intsig=-1;

for(iLoop=1;iLoop<=n;iLoop++)

{

sig*=-1;

sum+=sig*1.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*x+5*x+4;

}

voidmain()

{

intx=2;

printf("y1=%fn",fun(x));

printf("y2=%fn",fun(x+15));

printf("y3=%fn",fun(sin(x)));

}

第八章

一.选择题

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

8.12C

8.13110

8.1471

8.15(1)char*p=&ch;(2)p=&ch;(3)scanf("%c",p);(4)*p='A';

(5)printf("%c",*p);

8.16(1)s=p+3;(2)s=s-2(3)50(4)*(s+1)(5)2(6)1020304050

三.编程题

8.17

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

{

*sum=x+y;

*div=x-y;

return;

}

8.18

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

{

*max=x;

*min=x;

if(*max

{

*max=y;

}

if(*max

{

*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.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]>='0'&&str[iLoop]<='9'){

counter[str[iLoop]-'0']++;

}

iLoop++;

}

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

{

printf("%d-%dn",iLoop,counter[iLoop]);}

return0;

}

9.28

voidfun(intarray[],intarraysize,intstart){

intiLoop;

if(start

{

if(start<=0)

{

start=1;

}

for(iLoop=start;iLoop

{

array[iLoop-1]=array[iLoop];

}

}

for(iLoop=0;iLoop

{

printf("No.%d=%dn",iLoop,array[iLoop]);

}

}

9.29

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

{

intiLoop;

intcounter=0;

for(iLoop=0;iLoop

{

if(arry1[iLoop]%2)

{

arry2[counter++]=arry1[iLoop];

}

}

returncounter;

}

9.30

voidfun(chararray[],intarraysize)

{

intiLoop1;

intiLoop2;

chartemp;

/*冒泡排序*/

for(iLoop1=0;iLoop1

{

for(iLoop2=0;iLoop2

if(array[iLoop2]

{

temp=array[iLoop2];

array[iLoop2]=array[iLoop2+1];

array[iLoop2+1]=temp;

}

}

}

}

#include

voidfun(intarray[],intarraysize,intinertNumber){

intiLoop;

intiLoop2;

if(array[0]

{

for(iLoop=0;iLoop

{

if(array[iLoop]>inertNumber)

{

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

array[iLoop2+1]=array[iLoop2];

}

array[iLoop]=inertNumber;

break;

}

}

if(iLoop>=arraysize)

{

array[arraysize]=inertNumber;

}

}

el

{

for(iLoop=0;iLoop

{

if(array[iLoop]

{

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

array[iLoop2+1]=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("%d",a[iLoop]);

}

printf("n");

fun(a,6,0);

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

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

}

printf("n");

fun(a,7,4);

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

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

}

printf("n");

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--){

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

{

iLoop2=0;

x=rand()%20;

do

{

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

{

x=rand()%20;

iLoop2=0;

}

iLoop2++;

}while(iLoop2

array[iLoop]=x;

}

}

intmain()

{

inta[N];

intiLoop;

fun(a,N);

for(iLoop=0;iLoop

{

printf("%dn",a[iLoop]);

}

return0;

}

第十章

一.选择题

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

10.10C

二.填空题

10.11GFEDCB

10.12XYZ

10.13SO

10.1410

10.15Itis

10.16strlen(str)-1j--

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;

intiLoop1;

intiLoop2;

intresult=1;

len=strlen(str);

for(iLoop1=0,iLoop2=len-1;iLoop1

iLoop2--){

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

{

result=0;

break;

}

}

returnresult;

}

intmain()

{

chara[20]="ABCDCBA";

charb[20]="ABCDEBA";

printf("%dn",fun(a));

printf("%dn",fun(b));

return0;

}

10.21

charfun(char*str,intpos)

{

intlen;

intiLoop;

charch;

len=strlen(str);

if(pos>len)

{

returnNULL;

}

ch=str[pos];

for(iLoop=pos;iLoop

str[iLoop]=str[iLoop+1];

}

str[len-1]='0';

returnch;

}

第十一章

一.选择题

11.1D11.2B11.3A11.4C

二.填空题

11.5IJKLEFGHABCD

11.67

11.78

11.8*(s+j)i+1i

11.917

11.10(*fun)()(*fun)(a+i*h)/hmypoly

三.编程题

11.11

#include

#include

#defineN81

intmain(intargc,char**argv)

{

charsig;

intdig;

intpos;

charstr[N]={'0'};

charoutStr[N]={'0'};

if(argc<2)

{

sig='-';

dig=10;

}

el

{

sig=argv[1][0];

dig=argv[1][1]-'0';

}

printf("请输入一个字符串:");gets(str);

if(sig=='-')

{

pos=strlen(str)-dig;

if(pos<=0)

{

pos=0;

}

strcpy(outStr,str+pos);

}

elif(sig=='+')

{

strcpy(outStr,str);

pos=strlen(outStr);

if(pos>dig)

{

pos=dig;

}

outStr[pos]='0';

}

printf("处理后的字串为:");printf("%sn",outStr);

return0;

}

11.12

#include

#include

voidmovebin(char*bin)

{

intlen;

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)+'0';

n/=2;

fun(n,bin);

return;

}

intmain()

{

inta=4;

charbin[50]={""};

fun(a,bin);

printf("%sn",bin);

return0;

}

11.13

longfun(intn)

{

if(n==1)

{

returnn;

}

el

{

returnfun(n-1)+n;

}

}

intmain()

{

intnum;

intsum;

printf("请输入一个自然数:");scanf("%d",&num);

sum=fun(num);

printf("结果是:%dn",sum);

return0;

}

11.14

#include

intfun(intn)

{

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

{

return1;

}

el

{

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

}

intmain()

{

intresult;

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

scanf("%d",&num);

result=fun(num);

printf("斐波拉契级数为:%dn",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=11

13.9int*s*b

三.编程题

13.10

#defineMYALPHA(C)((C>='A'&&C<='Z')||(C>='a'&&C<='z'))?1:

013.11

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

13.12

#include

#include

intmain()

{

int*p;

inttmp;

intiLoop;

intiLoop2;

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

scanf("%d%d%d",p,p+1,p+2);

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

{

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

{

if(*(p+iLoop2)>*(p+iLoop2+1))

{

tmp=*(p+iLoop2);

*(p+iLoop2)=*(p+iLoop2+1);

*(p+iLoop2+1)=tmp;

}

}

}

printf("%d%d%dn",*p,*(p+1),*(p+2));

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[1],

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

array[iLoop].ave=(array[iLoop].s[0]+array[iLoop].s[1]+

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

}

return;

}

voidwriterec(structstudarray[],intsize)

{

intiLoop;

for(iLoop=0;iLoop{

printf("%st%st%dt%dt%dt%dt%fn",

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

array[iLoop].s[1],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

#include

#defineN100

structnode

{

intdata;

structnode*next;

intekMaxValue(structnode*pNode)

{

intmax;

structnode*pMove;

pMove=pNode;

max=pMove->data;

pMove=pMove->next;

while(pMove)

{

if(maxdata)

{

max=pMove->data;

}

pMove=pMove->next;

}

returnmax;

}

structnode*ekMaxValueAddress(structnode*pNode){

intmax;

structnode*maxAddress;

structnode*pMove;

pMove=pNode;

max=pMove->data;

maxAddress=pMove;

pMove=pMove->next;

while(pMove)

{

if(maxdata)

{

max=pMove->data;

maxAddress=pMove;

}

pMove=pMove->next;

}

returnmaxAddress;

}

intmain()

structnode*head;

structnode*pNode;

intiLoop;

head=(structnode*)malloc(sizeof(structnode));pNode=head;

pNode->next=NULL;

for(iLoop=0;iLoop{

pNode->next=(structnode*)malloc(sizeof(structnode));pNode=

pNode->next;

pNode->next=NULL;

pNode->data=iLoop;

}

printf("%dn",ekMaxValue(head->next));

printf("%dn",ekMaxValueAddress(head->next));

return0;

}

第十五章

一.选择题

15.1D15.2A15.3B15.4A

二.填空题

15.511110000

15.6a^a

15.7a|0xffff

15.8x|0xff00

15.9a=(012500>>2)

15.10ch|0x20

第十六章

一.选择题

16.1B16.2C

二.填空题

16.33!feof(f1)f2fclo(f1)fclo(f2)

16.4fopen(fname,"w")ch

16.5"r"!feof(fp)fgetc(fp)

16.6CCCCBBBBAAAA

三.编程题

16.7

#include

#defineN10

#defineLEN81

intmain()

{

char*str[N]={"AAAAAAAAA","BBBBBBBBB","CCCCCCCCC","DDDDDDDDD",

"EEEEEEEEE","FFFFFFFFF","GGGGGGGGG","HHHHHHHHH",

"IIIIIIIII",

"JJJJJJJJJ"};

charstr2[N][LEN];

FILE*fp;

intiLoop;

fp=fopen("","w");

if(fp==NULL)

{

printf("创建文件失败!n");return1;

}

el

{

for(iLoop=0;iLoop

fputs(str[iLoop],fp);

fputs("n",fp);

}

}

fclo(fp);

fp=fopen("","r");

if(fp==NULL)

{

printf("打开文件失败!n");return1;

}

el

{

for(iLoop=0;iLoop

fgets(str2[iLoop],LEN-1,fp);

}

}

fclo(fp);

for(iLoop=0;iLoop

printf("%s",str2[iLoop]);

}

return0;

}

16.8

#include

#defineN10

intmain()

{

floatnum;

intiLoop;

FILE*fp;

fp=fopen("","wb+");

if(fp==NULL)

{

printf("创建文件失败!n");return1;

}

/*从键盘读入10个数并写文件*/printf("请输入%d个数:",N);

for(iLoop=0;iLoop

scanf("%f",&num);

fwrite(&num,sizeof(num),1,fp);}

/*文件指针回到开始处*/rewind(fp);

/*从文件读出10个数并显示*/for(iLoop=0;iLoop

fread(&num,sizeof(num),1,fp);printf("%fn",num);

}

/*移文件指针到第四个数开始处*/fek(fp,3L*sizeof(num),SEEK_SET);

/*读入一个新数据*/

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

scanf("%f",&num);

fwrite(&num,sizeof(num),1,fp);

/*文件指针回到开始处*/

rewind(fp);

/*从文件读出10个数并显示*/

for(iLoop=0;iLoop

fread(&num,sizeof(num),1,fp);printf("%fn",num);

}

/*关闭文件*/

fclo(fp);

return0;

}

本文发布于:2023-01-30 07:50:53,感谢您对本站的认可!

本文链接:http://www.wtabcd.cn/fanwen/fan/88/161029.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:袁枚所见
下一篇:鲁滨孙飘流记
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图