当前位置:首页 > 2012年3月份二C题填空答案
printf(\ return 1; }
main()
{ char sfname[20] =\ FILE *myf; int i; char c; myf=fopen(sfname,\
printf(\
for(i=1; i<30; i++){ c='A'+rand()%;fprintf(myf,\ fclose(myf);printf(\
if (fun(sfname, tfname)) printf(\ else printf(\} 40
#include
struct list *next; } SLIST;
void fun( SLIST *h) { SLIST *p, *q; p=h->next; if (p!=NULL) { q=p->next;
while(q!=NULL)
{ if (p->data==q->data) { p->next=q->next; /**********found**********/
free(___1___); q 释放节点q 找到相同的数据时,
删除一个结点
/**********found**********/
q=p->___2___; next 这里是配合while循环,q指针后
移
}
else { p=q;
/**********found**********/
q=q->___3___; next 这里肯定是next ,q-> 后面只
能跟 data 和 next ,这里应该是填指针
} } } }
SLIST *creatlist(int *a)
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i { q=(SLIST *)malloc(sizeof(SLIST)); q->data=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf(\ else { printf(\ do { printf(\ p=p->next; } while(p!=NULL); printf(\ } } main( ) { SLIST *head; int a[N]={1,2,2,3,4,4,4,5}; head=creatlist(a); printf(\ outlist(head); fun(head); printf(\ outlist(head); } 41 程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是将形参a所指结构体变量s中的数据进行修改,并把a中地址作为函数值返回主函数,在主函数中输出修改后的数据。 例如:a所指变量s中的学号、姓名和3门课的成绩依次是:10001、”ZhangSan”、 95、80、88,修改后输出t中的数据应为:10002、”LiSi”、96、81、89。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include char name[10]; float score[3]; }; /**********found**********/ __1__ fun(struct student *a) struct student * 函数体类型,主要还 是看在主函数里,调用这个函数时需要的类型 { int i; a->sno = 10002; strcpy(a->name, \/**********found**********/ for (i=0; i<3; i++) __2__ += 1; a->score[i] 这个事具体的结构体 的成绩,自己对应画出结构体,看看是哪个部分 /**********found**********/ return __3__ ; a 返回的是函数体指针 } main() { struct student s={10001,\ *t; int i; printf(\ printf(\ Name: %s\\nScores: \ for (i=0; i<3; i++) printf(\ printf(\ t = fun(&s); printf(\ printf(\ Name: %s\\nScores: \ for (i=0; i<3; i++) printf(\ printf(\} 42 程序通过定义学生结构体数组,存储了若干名学生的学号、姓名和3门课的成绩。函数fun的功能是将存放学生数据的结构体数组,按照姓名的字典(从小到大) 排序。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include char name[10]; float score[3]; }; void fun(struct student a[], int n) { /**********found**********/ __1__ t; struct student 注意变量 t 是 结构体类型 int i, j; /**********found**********/ for (i=0; i<__2__; i++) n-1 排序,可以最后一个不排序 for (j=i+1; j /**********found**********/ if (strcmp(__3__) > 0) a[i].name,a[j].name 这里是 比较字符串是否相同 { t = a[i]; a[i] = a[j]; a[j] = t; } } main() { struct student s[4]={{10001,\ {10003,\87}}; int i, j; printf(\ for (j=0; j<4; j++) { printf(\ Name: %-8s Scores: \ for (i=0; i<3; i++) printf(\ printf(\ } fun(s, 4); printf(\ for (j=0; j<4; j++) { printf(\ Name: %-8s Scores: \ for (i=0; i<3; i++) printf(\ printf(\
共分享92篇相关文档