正在加载图片...
www.greatc.cn4月上机考试题库填空题 printf("nThe result is: %d\nin" n); outlist(head fun(head) printf(" The list after sorting: n"); 15、给定程序中函数fun的功能是将带头节点的单向链表结 outlist(head) 点数据域中的数据从小到大排序。即若原链表结点数据域从} 头至尾的数据为:10、4、2、8、6,排序后链表结点数据域 从头至尾的数据为:2、4、6、8、10 16、程序通过定义学生结构体变量,存储了学生的学号、姓 请在程序的下划线处填入正确的内容并把下划线删除,名和3门课的成绩。函数fun的功能是将形参a所指结构体 使程序得出正确的结果 变量s中的数据进行修改,并把a中地址作为函数值返回主函 注意:源程序存放在考生文件夹下的 BLANK1C中 数,在主函数中输出修改后的数据 不得增行或删行,也不得更改程序的结构 例如:a所指变量s中的学号、姓名、和三门课的成绩 #include <stdio. h> 依次是:10001、" ZhangSan"、95、80、88,修改后输出t #include <stdlib. h> 中的数据应为:10002、"Lisi"、96、81、89 #definen 6 请在程序的下划线处填入正确的内容并把下划线删除 typedef struct node i 使程序得出正确的结果 int data 主意:源程序存放在考生文件夹下的 BLANKLO中 struct node 'next; 不得增行或删行,也不得更改程序的结构! A NODE; void fun(NODE *h) ing h 率*布布亭事 found*事事率*布率事*/ sno har name [10] while(p) float score3]: 率*布率率事事布 found布率率事事摩*/ /率事率布事事 found市事事率率事率*/ fun(struct student *a) /率*率事率率事foud市率率布率率*/ if(p->data 3 q->data) a->sno=10002 i t= p->data, p->data = q->data, q->data strcpy(a->name, "LiSi") /率率率 found水本率事**/ for(=0,i<3;计++) mainO NODE*creatlist(int aD) i struct student s=f10001, ZhangSan,95, 80, 88),*t Int I. h=(NODE*malloc(sizeof(NODE)); printf("nn The original data n"); h->next= NULL, printf("nNo: %ld Name: %slnScores: "ssno, s name); for(i=0;i<N;计 for(F0; 1<3: 1++) printf("%6.2f ",sscore) i q(NODE")malloc(sizeof(NODE); printf("n"); g->next= NULL printf("nThe data after modified n"); if(h->next==NULL) h->next=p=q: printf("nNo: %ld Name: %sunCor else p->next= p=4; j for(F0; K<3: 1++) printf("%6.2f", t->scoreD return printf("n"); void outlist(NODE·h) NODE·p 17、给定程序中,函数fun的功能是:计算形参x所指数组 p=h->next, 中N个数的平均值(规定所有数均为正数),将所指数组中 if(p=NULL) printf("The list is NULL! n") 大于平均值的数据移至数组的前部,小于等于平均值的数据 移至x所指数组的后部,平均值作为函数值返回,在主函数 i printf("nHead " 中输出平均值和移动后的数据。 例如,有10个正数:463032406174515 printi("->%d", p->data), p=p->next; 4826,平均值为:30.500000 while(p!=NULL); 移动后的输出为:463240454830617 printf("->EndIn"); 请在程序的下划线处填入正确的内容并把下划线删除 使程序得出正确的结果 注意:源程序存放在考生文件夹下的 BLANKLC中 i NODE*head 不得增行或删行,也不得更改程序的结构! int aIN]={0,10,4,2,8,6} #include <stdlib. h> head=creatlist(a) #include <stdio. h> printf("\n The original list: In"); #define N 10宏为世纪教育 www.greatc.cn 4 月上机考试题库 填空题 5 printf("\nThe result is: %d\n\n",n); } 15、给定程序中,函数 fun 的功能是将带头节点的单向链表结 点数据域中的数据从小到大排序。即若原链表结点数据域从 头至尾的数据为:10、4、2、8、6,排序后链表结点数据域 从头至尾的数据为:2、4、6、8、10。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #include <stdlib.h> #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; /**********found**********/ p = __1__ ; while (p) { /**********found**********/ q = __2__ ; while (q) { /**********found**********/ if (p->data __3__ q->data) { t = p->data; p->data = q->data; q->data = t; } q = q->next; } p = p->next; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h = (NODE *)malloc(sizeof(NODE)); h->next = NULL; for(i=0; i<N; i++) { q=(NODE *)malloc(sizeof(NODE)); q->data=a[i]; q->next = NULL; if (h->next == NULL) h->next = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p = h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]= {0, 10, 4, 2, 8, 6 }; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after sorting :\n"); outlist(head); } 16、程序通过定义学生结构体变量,存储了学生的学号、姓 名和 3 门课的成绩。函数 fun 的功能是将形参 a 所指结构体 变量 s 中的数据进行修改,并把 a中地址作为函数值返回主函 数,在主函数中输出修改后的数据。 例如:a 所指变量 s 中的学号、姓名、和三门课的成绩 依次是:10001、" ZhangSan "、95、80、88,修改后输出 t 中的数据应为:10002、"LiSi "、96、81、89。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #include <string.h> struct student { long sno; char name[10]; float score[3]; }; /**********found**********/ __1__ fun(struct student *a) { int i; a->sno = 10002; strcpy(a->name, "LiSi"); /**********found**********/ for (i=0; i<3; i++) __2__ += 1; /**********found**********/ return __3__ ; } main() { struct student s={10001,"ZhangSan", 95, 80, 88}, *t; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",s.sno, s.name); for (i=0; i<3; i++) printf("%6.2f ", s.score[i]); printf("\n"); t = fun(&s); printf("\nThe data after modified :\n"); printf("\nNo: %ld Name: %s\nScores: ",t->sno, t->name); for (i=0; i<3; i++) printf("%6.2f ", t->score[i]); printf("\n"); } 17、给定程序中,函数 fun 的功能是:计算形参 x 所指数组 中 N 个数的平均值(规定所有数均为正数),将所指数组中 大于平均值的数据移至数组的前部,小于等于平均值的数据 移至 x 所指数组的后部,平均值作为函数值返回,在主函数 中输出平均值和移动后的数据。 例如,有 10 个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 移动后的输出为:46 32 40 45 48 30 6 17 15 26 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdlib.h> #include <stdio.h> #define N 10
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有