四川省计算机等级考试二级C语言笔试题(第二十一次)一 联系客服

发布时间 : 星期六 文章四川省计算机等级考试二级C语言笔试题(第二十一次)一更新完毕开始阅读

)))))))) # include main(int argc, char *argv[]) { FILE *fp; int fun(FILE *); int num,i=1; while(--argc>0)

if((fp=fopen(argv[i++],\ { printf(\ exit(0); }

else {num=fun(fp) ; fclose(fp); } printf(\ }

int fun(FILE *fp) { static int count=0; char c; c=fgetc(fp); while(c!=EOF)

{ if(c>='0'&&c<='9') count++; c=fgetc(fp); }

return(count); }

)))))))) )))))))) 上述C程序经编译、连接后生成一个名为2_3.exe的可执行文件,假

设盘上有两个文本文件file1.dat 和file2.dat,file1.dat的内容为123abc,file2.dat的内容为xyz ABC 987。

(1)若在DOS提示符下键入:2_3 file1.dat file2.dat<回车>,则程序的运行结果为( 38 )。

38(A)num=3 (B)num=4 (C)num=5 (D)num=6 (2)若将fun函数中对count的定义static int count=0;改为int count=0;其余条件不变,则在DOS提示符下键入:2_3 file1.dat file2.dat<回车>,则程序的运行结果为( 39 )。

39(A)num=3 (B)num=4 (C)num=5 (D)num=6 (3)若将fun函数中对count的定义static int count =0;改为int count;其余条件不变,则在DOS提示符下键入:2_3 file1.dat file2.dat<回车>,则程序的运行结果为( 40 )。

40(A)num=4 (B)num=5 (C)num=6 (D)随机值

四川省计算机等级考试二级C语言笔试题(第二十一次) 三 2009-03-29 15:23:02

注意:① 请把下面“程序填空”中各小题答案写在主观题答题纸上

② 每一个空只填一个语句或一个语句所缺的部分内容

三、程序填空(每空2分,共30分)

1.以下程序能创建一张包含有4名学生信息的单向链表并输出。

# include # include

)))))))) )))))))) # define LEN sizeof(struct student) struct student { int data; ① ; }; int num=1;

struct student *creat()

{ struct student *head,*p1,*p2;

head=p1=p2=(struct student *)malloc(LEN); scanf(\ while(num<4)

{ p1=(struct student *)malloc(LEN); scanf(\ ② ; p2=p1; num++; }

p2->next=NULL; return(head); } main()

{ struct student *head,*p; head=creat(); p=head;

)))))))) )))))))) if(head!=NULL)

do{ printf(\ ③ ; }while(p!=NULL); }

2.下面程序功能是在一个字符串中找出最大的字符并放在第一个位

置上,并将该字符前的原字符往后顺序移动,如:cbyab 变成ycbab。

# include # include main()

{ char str[80],*p=str,*q,max; gets(p); max=*(p++); while(*p!=0) { if(max<*p) { max=*p; ① ; } p++; } p=q;

while(② ) { *p=*(p-1);p--; } ③ ;

))))))))