if (flag) {
ptr=s+strlen(s); ptr1=t; } else {
ptr=t+strlen(t); ptr1=s }
for (;*ptr1!='\\0';ptr1++,ptr++) *ptr=*ptr1; *ptr='\\0'; }
4.设有如下类型定义和变量说明 struct node {
int data
struct node *next; };
struct node *head
并设已生成如下之带头结点的正向线性链表图
阅读下述程序段 struct node *p,*q,*r; p=head->next; if (!p=NULL)
while (p->next!=NULL) { q=p;
while (q->next!=NULL) {
if (q->next->data==p->data) {
r=q->next;
q->next=q->next->next; free(r);
head->data=head->data-1; } else
q=q->next; }
p=p->next; }
请画出执行此程序段所形成的新正向线性链表图。 5.阅读下述程序 #inclued
int i,days; struct {
int month; int day; int year; }date;
int daytab[13]={0,31,28,31,30,31,31,30,31,30,31}; printf(\
scanf(\ days=0;
for (i=1;i if ((date.year%4==0&&date.year0!=0|| date.year%4==0)&&date.month>=3) days+=1; printf(\ date.month,date.day,days,date.year); } 假定本程序先后运行三次。 (1)第一次运行时,若有 Enter month,day,year: (2)第二次运行时,若有 Enter month,day,year: (3)第三次运行时,若有 Enter month,day,year: 请分别写出每次运行的输出结果。 6.写出执行下述程序的输出结果。 #include int i,n; FILE *fp; if ((fp=fopen(\ { printf(\ exit(0); } for (i=1;i<=10;i++) fprintf(fp,\ for (i=0;i<5;i++) { fseek(fp,i*6L,SEEK_SET); fscanf(fp,\ printf(\ } printf(\ fclose(fp); } 四、程序设计题(每题10分,共20分) 1.n(n0)阶勒让德多项式的递推公式为 编写两个求n(设n0)阶勒德多项式的递归函数定义,其中一个使用if语句实现,另一个使用switch语句实现。请填空。(注意:(2)用在两处) 求n(n0)阶勒让德多项式的递归函数定义(使用if语句实现) float p(float x,int n) { if (n==0) return (1); else if(____(1)_____) return (x); else return(_____________(2)____________); } 求n(n0)阶勒让德多项式的递归函数定义(使用switch语句实现) float p(float x,int n) { float y; switch (_____(3)______) { case 0:y=1;break; case 1:y=x;break; _________(4)_______:y=______________(2)_____________; } return (________(5)_________); } 2.设已定义 #define ITEM struct item #define SIZE sizeof(ITEM) ITEM { int num; ITEM *next; }; ITEM *head; 下述函数定义实现将一数值域num的值为 insno的新表元素插入至已知线性链表(不带头线结点)中数值域num的值为tono的表元素(设该表元素原已存在)之前。原链表的首地址由形参head所指向,新链表的首地址通过函数值返回。请填空完善程序。 ITEM *insbefore(ITEM *head,int insno,int tono) { ITEM *insp,*top,*prep; insp=(ITEM *)malloc(SIZE); insp->num=insno; if (tono==head->num) /*插第一个表元素之前*/ { insp->next=head; ______(1)_________; } else { prep=head; tip=prep->next; while (top->num!=tono) { ________(2)___________; else /*插其他表元素之前 */ { prep=head; top=prep->next; while (top->num!=tono) { __________(2)_________; /*prep与top均 */ __________(3)_________; /*各指向下一表元素 */ } insp->next=top; ___________(4)__________; } return (_______(5)_________); } 模拟试卷(二)参考解答 一、单项选择题(每题1分,共20分) 1.(3) 2.(4) 3.(3) 4.(3) 5.(4) 6.(4) 7.(2) 8.(1) 9.(4) 10.(3) 11.(1) 12.(2) 13.(4) 14.(1) 15.(3) 16.(3) 17.(2) 18.(3) 19.(3) 20.(1) 二、填充题(每空2分,共30分) 1.x>4||x<-4(或x<-4||x>4) 2.j%3!=0(或j%3) 3.1.0/(k*(k+1)) 4.i%j==0(或!(1%j) 5.AB 6.s1[i]-s2[i] 7.LANGUAGE 8.*x=sum 9.Thatsit 10.7,5 11.sqrt(6*s)(或sqrt(6.0*s)) 12.p->next 13.count++(或count=count+1,或++count) 14.二进制文件夹 15.(enum days)(((int)today+3)%7) 三、程序分析题(每题5分,共30分) 1.The 5*5 matrix generated: 25 16 9 4 1 16 9 4 1 25 9 4 1 25 16 4 1 25 16 9 1 25 16 9 4 2.101 96 81 74 35 30 28 19 17 2 3.abcd1234 1234abcd1234 4. 5.(1)month 10 day 1 is the 275th day in 2000. (2)month 8 day 9is the 221th day in 1939. (3)month 2 day 10 is the 41th day in 2000. 6.1 3 5 7 9 四、程序设计题(每题10分,共20分) 1.(1)n==1 (2)((2*n-1)*x*p(x,n-1)-(n-1)*p(x,n-2))/n (3)n (4)default (5)y 2.(1)head=insp (2)top=top->next (3)prep=prep->next (4)prep->next=insp (5)head 注(2)、(3)可互换。