《C语言程序设计》(高等教育出版社)湖南省(对口升学)计算机类 高频考点冲刺卷(五)

2026-03-27
| 2份
| 45页
| 42人阅读
| 1人下载

资源信息

学段 中职
学科 职教专业课
课程 C语言程序设计
教材版本 C语言程序设计高教版(第五版)全一册
年级 高一
章节 第3章 分支结构程序设计,第6章 函数,第8章 指针
类型 题集-专项训练
知识点 数据类型和简单程序设计,循环结构,数组,函数,指针
使用场景 中职复习
学年 2026-2027
地区(省份) 湖南省
地区(市) -
地区(区县) -
文件格式 ZIP
文件大小 293 KB
发布时间 2026-03-27
更新时间 2026-03-27
作者 糖醋排骨009
品牌系列 学易金卷·阶段检测模拟卷
审核时间 2026-03-27
下载链接 https://m.zxxk.com/soft/57044317.html
价格 3.00储值(1储值=1元)
来源 学科网

内容正文:

编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(五)解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.下列程序段的运行结果是( ) char s[]=“ABC”,*p=s;printf(“%d ”,*(p+3)); A.67 B.0 C.字符C的地址 D.C 【答案】B 【解析】指针变量p指向的是字符串的首地址,p+3指向了字符串结束标志’\0’,因此,*(p+3)的值为’\0’,其ASCII码值为0。 2.设a、b和c都是int型变量,且a=3、b=4、c=5,则下面的表达式中,值为0的表达式是( ) A.'a'&&'b' B.a<=b C.a||+c&&b-c D.!((a<b)&&!cll1) 【答案】D 【解析】!a<b)&&!c||1),此表达式先运算最外面括号内的表达式(a<b)&&!c|1,然后再进行非运算,由于(a<b)&&!c|1中先算小括号内的a<b结果为1,再按逻辑运算符的运算顺序:!,&&,,进行运算后得(a<b)&&!cl|1的值为1,所以最后再进行非运算知D选项的运算结果为0。本题答案为D。 3.以下对结构变量stu中成员age的非法引用是( ) Struct student { int age; int num;}stu,*p; P=&stu; A.stu.age B.student.age C.p->age D.(*p).age 【答案】B 【解析】student 是结构体类型名,不能直接使用类型名访问成员,必须通过结构体变量 stu、指针 p、*p 来访问,因此 student.age 属于非法引用。 4.以下运用if语句判断x和y大小的程序段,错误的是( ) A.if(x>y) printf(" x>y "); if(x<y) printf(" x<y "); else printf(" x=y "); B.if(x>=y) if(x>y) printf("x>y"); else printf("x=y"); else printf("x<y"); C.if(x>y) printf("x>y"); if(y>x) printf("x<y"); if(x==y) printf(" x=y "); D.if(x>y) printf("x>y"); else if(y<x) printf("x<y"); else printf(" x=y "); 【答案】A 【解析】C语言中规定,else子句总是与前面最近的不带else的if相结合,所以A选项中,第二个if语句中,当X>=y时,均会输出x=y,故选项A错误。 5.若已定义:int a[9],*p=a;并在以后的语向中未改变p的值,不能表示a[1]地址的表达式是( ) A.p+1 B.a+1 C.a++ D.++P 【答案】C 【解析】选项C中,数组名所表示的数组地址不能被重新赋值。本题答案为C. 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include<stdio.h> main() { int i,t,j,s=0; int b[10]={0,1,2,3,4,5,6,7,8,9}; int n=sizeof(b)/sizeof(b[0]); for(i=0;i<n/2;i++) { t=b[i]; b[i]=b[n-t-1]; b[n-t-1]=i;} for(j=5;j<10;j++) s+=b[j]; printf("%d ",s); } 【答案】10 (2)下列程序的运行结果是_________________。 #include <stdio.h> struct Data { int x; int y; }; main() { struct Data d[] = {{3, 1}, {1, 3}, {2, 2}}; int i, j; for (i = 0; i < 2; i++) { for (j = i + 1; j < 3; j++) { if (d[i].x > d[j].x) { struct Data t = d[i]; d[i] = d[j]; d[j] = t; } } } printf("%d,%d ", d[0].y, d[2].y); } 【答案】3,1 (3)下列程序的运行结果是_________________。 #include <stdio.h> int main() { int a[] = {8, 3, 9, 2, 7, 4, 6, 1, 5}; int n = 9, left = 0, right = n - 1; int threshold = 5,t,i,sum; while (left < right) { while (left < right && a[left] <= threshold) { left++; if (a[left] % 2 == 0) threshold--; } while (left < right && a[right] > threshold) { right--; } if (left < right) { t = a[left]; a[left] = a[right]; a[right] = t; threshold += 1; } } sum = 0; for (i = 0; i < n; i++) { if (i % 2 == 0) sum += a[i]; } printf("%d ", sum); } 【答案】27 (4)下列程序的运行结果是_________________。 #include <stdio.h> #include <string.h> struct Item { int id; int weight; char code[5]; }; main() { struct Item items[]={{101,50,"C01"},{102,30,"A02"},{103,50,"B03"}, {104,20,"D04"}}; int n = 4,i,total,j,swap; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - 1 - i; j++) { swap = 0; if (items[j].weight < items[j+1].weight) { swap = 1;} else if (items[j].weight == items[j+1].weight) { if (strcmp(items[j].code, items[j+1].code) > 0) { swap = 1; } } if (swap) { struct Item t = items[j]; items[j] = items[j+1]; items[j+1] = t; } } } total = 0; for (i = 0; i < n; i++) { total += items[i].id * (i + 1);} printf("%d ", total);} 【答案】1027 (5)下列程序的运行结果是_________________。 #include <stdio.h> main() { int a[] = {1, 2, 3, 4, 5}; int i = 0; int s = 0; while (i < 5) { s += *(a + i) * (i % 2 == 0 ? 1 : -1); i++; if (s < 0) s = 0; } printf("%d ", s); } 【答案】5 (6)下列程序的运行结果是_________________。 #include <stdio.h> int process_matrix(int mat[][4], int rows) { int sum = 0,i,j; for(i = 0; i < rows; i++) { for(j = 0; j < 4; j++) { if(i == 0 || j == 0 || i == rows-1 || j == 3) { sum += mat[i][j]; } else { sum -= mat[i][j]; } } } return sum;} main() { int matrix[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}}; int (*ptr)[4] = matrix; int result = 0,i,j; for(i = 0; i < 2; i++) { result += process_matrix(ptr + i, 2); } printf("%d ", result); for(i = 0; i < 3; i++) { for(j = 0; j < 4; j++) { if(i + j == 3) { printf("%d ", matrix[i][j]); } } } printf(" ");} 【答案】104 4 7 10 (7)下列程序的运行结果是_________________。 #include<stdio.h> main() { int i=0; char a[ ]="abm",b[ ]="aqid",c[10]; while(a[i]!='\0'&&b[i]!='\0') { if(a[i]>=b[i]) c[i]=a[i]-32; else c[i]=b[i]-32; i++;} c[i]='\0'; puts(c);} 【答案】AQM 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是把形参s所指字符串中最右边的n个字符复制到形参t所指字符数组中,形成一个新字符串。若s所指字符串的长度小于n,则将整个字符串复制到形参t所指字符数组中。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> #include <string.h> #define N 80 void fun(__________①___________) {int len,i,j=0; len=strlen(s); if(n>=len) _______②________; else { for(i=________③______;i<=len-1;i++) t[j++]=s[i]; _______④_____; } } main() { char s[N],t[N];int n; printf("Enter a string:"); gets(s); printf("Enter n:"); scanf("%d",&n); fun(s,n,t); printf("The stringt:"); puts(t); } 【答案】①char *s, int n, char *t ②strcpy(t,s) ③len-n ④t[j]='\0' (2)中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,下列程序的功能是,得出这个人在以后的某一天中是“打鱼”还是“晒网”。(4空) #include<stdio.h> int days(struct date day); struct date{ int year; int month; int day; }; int main() { struct date today,term; int yearday,year,day; printf("Enter year/month/day:"); scanf("%d%d%d",&today.year,&today.month,&today.day); term.month=12; term.day=31; for(yearday=0,year=1990;year<today.year;year++) { term.year=year; ________①________; } yearday+=days(today); day=_______②_______; if(day>0&&day<4) printf("he was fishing at that day. "); else printf("He was sleeping at that day. "); } int days(struct date day) { static int day_tab[2][13]= {{0,31,28,31,30,31,30,31,31,30,31,30,31,}, {0,31,29,31,30,31,30,31,31,30,31,30,31,}}; int i,lp; lp=___________③_____________; for(i=1;i<day.month;i++) day.day+=_______④_______; return day.day; } 【答案】①yearday+=days(term) ②yearday%5 ③day.year%4==0&&day.year%100!=0||day.year%400==0 ④day_tab[lp][i] (3)A、B、C、D、E五个人在某天夜里合伙去捕鱼,到第二天凌晨时都疲惫不堪,于是各自找地方睡觉。日上三杆,A第一个醒来,他将鱼分为五份,把多余的一条鱼扔掉,拿走自己的一份。B第二个醒来,也将鱼分为五份,把多余的一条鱼扔掉,保持走自己的一份。C、D、E依次醒来,也按同样的方法拿走鱼。下列程序的功能是求出他们合伙至少捕了多少条鱼。请填空。(4空) #include<stdio.h> int main() { int n,i,x,flag=1; for(n=6;flag;n++) { for(x=n,i=1&&______①_______;i<=5;i++) if((x-1)%5==0) x=_______②_______; else _____③______; if(flag) _______④______; else flag=1; } printf("Total number of fish catched=%d ",n); } 【答案】①flag ②4*(x-1)/5 ③flag=0 ④break (4)在main()函数内输入10个整数到数组中,调用数据交换函数,将数组中最大数与最后一个数交换,最小数与第1个数交换。(3空) #include <stdio.h> void main() { int a[10], i; int *pmax, *pmin; ________①_________ printf("请输入10个整数:"); for(i=0;i<10;i++) scanf("%d",a+i); pmax=a; ________②________; for(i=1;i<10;i++) { if(*pmax<a[i]) pmax=&a[i]; if(*pmin>a[i]) pmin=&a[i]; } swap(pmax,&a[9]); _______③_______; printf("交换后的10个整数依次是: "); for(i=0;i<10;i++) printf("%d\t",a[i]); printf(" "); } void swap(int *px,int *py) { int temp; temp=*px; *px=*py; *py=temp; } 【答案】①void swap(int *px,int *py); ②pmin=a ③swap(pmin,&a[0]) (5)从键盘输入若干行字符(最后一行按Enter键时表示输入结束),将它们存入磁盘文件中,再读出这些字符,将其中的大写字母转换成小写字母后写入另一磁盘文件中。(3空) #include <stdio.h> #include <stdlib.h> #include <string.h> void main() { int i=0; FILE *fp,*fp1; char str[100],fname[50],fnamel[50]; printf("请输入两个文件名: "); gets(fname); gets(fnamel); if((fp=fopen(fname,"w+"))==NULL) { printf("不能打开第1个文件,写文件失败! "); exit(0); } if((fp1=fopen(fnamel,"w"))==NULL) { printf("不能打开第2个文件,写文件失败! "); exit(0); } printf("请输入若干行文字: "); while(__________①__________) { fputs(str,fp); fputs(" ",fp); } _________②________; while(fgets(str,100,fp)!=NULL) { for(i=0;_________③__________;i++) if(str[i]>='A' && str[i]<='Z') str[i]=str[i]+32; printf("%s",str); fputs(str,fp1); } fclose(fp); fclose(fp1); } 【答案】①strlen(gets(str))>0 ②rewind(fp) ③str[i]!=' ' 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)在此程序中,函数fun()的功能是读入一个字符串(长度<20),将该字符串中的所有字符按ASCII值升序排列后输出。例如,若输入"edcba",则应输出"abcde". 请改正程序中的错误,使它能得出正确的结果。以下程序只允许修改两行。 L1 #include <string.h> L2 #include <stdio.h> L3 void fun(char t[]) L4 { L5 char c; L6 int i,j; L7 for(i=strlen(t);i;i--) L8 for(j=0;j<i;j++) L9 if(t[j]<t[j+1]) L10 { L11 c=t[j]; L12 t[j]=t[j+1]; L13 t[j+1]=c; L14 } L15 } L16 main() L17 { L18 char s[81]; L19 printf(" Please enter a char- acter string :"); L20 gets(s); L21 printf(" Before sorting : %s",s); L22 fun(s); L23 printf(" After sorting decend-ingly: %s",s); L24 } ①___________________________________________________ ②___________________________________________________ 【答案】①L7 for(i=strlen(t)-1;i;i--) ②L9 if(t[j]>t[j+1]) (2)在此程序中,请编写函数fun(),它的功能是求出能整除x且不是偶数的整数,并将这些整数按从小到大的顺序放在pp所指的数组中,总个数通过形参n返回。以下程序只允许修改三行。 L1 #include <stdio.h> L2 #include <stdlib.h> L3 void fun(int x,int pp[],int *n) L4 { L5 int i,j=0; L6 for(i=1;i<=x;i=i+2) L7 if(x%i==0) L8 pp[j]=i; L9 n=j; L10 } L11 main() L12 { L13 FILE *wf; L14 int x,aa[1000],n,i; L15 system("CLS"); L16 printf(" Please enter an integer number: "); L17 scanf ("%d",&x); L18 fun (x, aa, n); L19 for (i=0;i<n;i++) L20 printf ("%d ",aa[i]); L21 printf (" "); L22 wf=fopen("out.dat","w"); L23 fun(30, aa, &n); L24 for(i=0;i<n;i++) L25 fprintf (wf,"%d ", aa[i]); L26 fclose(wf); L27 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 【答案】①L8 pp[j++]=i; ②L9 *n=j; ③L18 fun (x, aa, &n); (3)下列程序的功能是:任意两个正整数的最大公约数和(GCD)和最小公倍数(LCM)。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int a,b,num1,num2,temp; L5 printf("Input a & b:"); L6 scanf("%d%d",&num1,&num2); L7 if(num1<num2) L8 { temp=num1; L9 num1=num2; L10 num2=temp; } L11 a=num1; L12 b=num2; L13 while(b!=0) L14 { temp=a/b; L15 a=b; L16 b=temp; } L17 printf("The GCD of %d and %d is: %d ",num1,num2,a); L18 printf("The LCM of them is: %d ",num1*num2/a); L19 } ①___________________________________________________ ②___________________________________________________ 【答案】①L7 if(num1>num2) ②L14 { temp=a%b; (4)下面程序的功能是:求不超过1000的回文素数。所谓回文素数是指,对一个整数n从左向右和从由向左读其结果值相同且是素数,即称n为回文素数。以下程序只允许修改三行。 L1 #include<stdio.h> L2 int a(int n); L3 int main() L4 { L5 int i,j,t,k,s; L6 printf("Following are palindrome primes not greater than 1000: "); L7 for(i=0;i<=9;++i) L8 for(j=0;j<=9;++j) L9 for(k=0;k<=9;++k) L10 { L11 s=i*100 + j*10 + k; L12 t=i*100 + j*10 + k; L13 if(i == 0 && j==0) L14 { t=t/100; } L15 else if(i ==0) L16 { t = j*10; } L17 if(s>10&& s=t&&a(s)) L18 { printf("%d\t",s); } L19 } L20 return 0; } L21 int a(int n) L22 { int i; L23 for(i=2;i<(n-1)/2;i++) L24 { if(n%i == 0) L25 return 0; } L26 return 1; } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 【答案】①L12 t=i*100 + j*10 + i; ②L16 { t = j*10 + j; } ③L17 if(s>10 && s==t && a(s)) 三、程序设计题(本大题共2小题,合计20分) 1.下列程序的功能是:从链表中删除总和为0的连续节点序列,返回头节点。(每空2分,共10分) 输出结果为: 原始链表: 1 2 -3 3 1 删除和为0的连续节点后: 3 1 #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode *removeZeroSumSublists(struct ListNode* head) { struct ListNode* dummy = NULL; struct ListNode* curr = NULL; struct ListNode* start = NULL,* result; int sum = 0; int found = 0; dummy = ____________①___________; dummy->val = 0; dummy->next = head; start = dummy; while (start != NULL) { curr = _________②_________; sum = 0; found = 0; while (curr != NULL) { sum += curr->val; if (sum == 0) { start->next = _________③_________; found = 1; break; } curr = curr->next; } if (___________④_________) { start = start->next; } } result = dummy->next; free(dummy); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode* head = NULL; struct ListNode* tail = NULL; int i = 0; if (n == 0) { return NULL; } for (i = 0; i < n; i++) { struct ListNode* node = NULL; node = (struct ListNode*)malloc(sizeof(struct ListNode)); node->val = arr[i]; node->next = NULL; if (head == NULL) { head = node; tail = node; } else { tail->next = node; tail = node; } } return head; } void printList(struct ListNode* head) { struct ListNode* curr = head; while (curr != NULL) { printf("%d ", curr->val); curr = curr->next; } printf(" "); } main() { int arr[] = {1, 2, -3, 3, 1}; int n = 5; struct ListNode* head = NULL; struct ListNode* result = NULL; head = createList(arr, n); printf("原始链表: "); printList(head); _____________⑤_____________ printf("删除和为0的连续节点后: "); printList(result); } 【答案】①(struct ListNode*)malloc(sizeof(struct ListNode)) ②start->next ③curr->next ④!found ⑤result = removeZeroSumSublists(head) 2.下列程序的功能是:使用归并排序法对创建的链表进行升序排列。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* merge(____________①___________) { struct ListNode dummy; struct ListNode* tail; dummy.next = NULL; tail = &dummy; while (l1 != NULL && l2 != NULL) { if (l1->val <= l2->val) { tail->next = l1; l1 = l1->next; } else { tail->next = l2; l2 = l2->next; } tail = tail->next; } tail->next = _________②__________; return dummy.next; } struct ListNode* mergeSort(struct ListNode* head) { struct ListNode dummy; struct ListNode* tail; struct ListNode* cur; struct ListNode* left; struct ListNode* right; int length; int size; int count; if (_____________③____________) { return head; } dummy.next = head; length = 0; cur = head; while (cur != NULL) { length++; cur = cur->next; } size = 1; while (__________④_________) { tail = &dummy; cur = dummy.next; while (cur != NULL) { left = cur; count = 1; while (count < size && cur->next != NULL) { cur = cur->next; count++; } right = cur->next; cur->next = NULL; count = 1; cur = right; while (______________⑤______________) { cur = cur->next; count++; } if (cur != NULL) { struct ListNode* nextSegment = cur->next; cur->next = NULL; cur = nextSegment; } tail->next = merge(left, right); while (tail->next != NULL) { tail = tail->next; } } size *= 2; } return dummy.next; } struct ListNode* createList(int arr[], int n) { struct ListNode* head; struct ListNode* tail; int i; struct ListNode* node; head = NULL; tail = NULL; for (i = 0; i < n; i++) { node = (struct ListNode*)malloc(sizeof(struct ListNode)); node->val = arr[i]; node->next = NULL; if (head == NULL) { head = node; tail = node; } else { tail->next = node; tail = node; } } return head; } void printList(struct ListNode* head) { struct ListNode* curr; curr = head; while (curr != NULL) { printf("%d ", curr->val); curr = curr->next; } printf(" "); } main() { int len, i; int* arr; struct ListNode* head; struct ListNode* sorted; printf("请输入链表节点个数:"); scanf("%d", &len); arr = (int*)malloc(len * sizeof(int)); printf("请输入 %d 个整数: ", len); for (i = 0; i < len; i++) { scanf("%d", &arr[i]); } head = createList(arr, len); printf(" 原始链表:"); printList(head); sorted = mergeSort(head); printf("排序后链表:"); printList(sorted); free(arr); } 【答案】①struct ListNode* l1, struct ListNode* l2 ②(l1 != NULL) ? l1 : l2 ③head == NULL || head->next == NULL ④size < length ⑤count < size && cur != NULL && cur->next != NULL 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $ 编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(五)解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.下列程序段的运行结果是( ) char s[]=“ABC”,*p=s;printf(“%d ”,*(p+3)); A.67 B.0 C.字符C的地址 D.C 2.设a、b和c都是int型变量,且a=3、b=4、c=5,则下面的表达式中,值为0的表达式是( ) A.'a'&&'b' B.a<=b C.a||+c&&b-c D.!((a<b)&&!cll1) 3.以下对结构变量stu中成员age的非法引用是( ) Struct student { int age; int num;}stu,*p; P=&stu; A.stu.age B.student.age C.p->age D.(*p).age 4.以下运用if语句判断x和y大小的程序段,错误的是( ) A.if(x>y) printf(" x>y "); if(x<y) printf(" x<y "); else printf(" x=y "); B.if(x>=y) if(x>y) printf("x>y"); else printf("x=y"); else printf("x<y"); C.if(x>y) printf("x>y"); if(y>x) printf("x<y"); if(x==y) printf(" x=y "); D.if(x>y) printf("x>y"); else if(y<x) printf("x<y"); else printf(" x=y "); 5.若已定义:int a[9],*p=a;并在以后的语向中未改变p的值,不能表示a[1]地址的表达式是( ) A.p+1 B.a+1 C.a++ D.++P 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include<stdio.h> main() { int i,t,j,s=0; int b[10]={0,1,2,3,4,5,6,7,8,9}; int n=sizeof(b)/sizeof(b[0]); for(i=0;i<n/2;i++) { t=b[i]; b[i]=b[n-t-1]; b[n-t-1]=i;} for(j=5;j<10;j++) s+=b[j]; printf("%d ",s); } (2)下列程序的运行结果是_________________。 #include <stdio.h> struct Data { int x; int y; }; main() { struct Data d[] = {{3, 1}, {1, 3}, {2, 2}}; int i, j; for (i = 0; i < 2; i++) { for (j = i + 1; j < 3; j++) { if (d[i].x > d[j].x) { struct Data t = d[i]; d[i] = d[j]; d[j] = t; } } } printf("%d,%d ", d[0].y, d[2].y); } (3)下列程序的运行结果是_________________。 #include <stdio.h> int main() { int a[] = {8, 3, 9, 2, 7, 4, 6, 1, 5}; int n = 9, left = 0, right = n - 1; int threshold = 5,t,i,sum; while (left < right) { while (left < right && a[left] <= threshold) { left++; if (a[left] % 2 == 0) threshold--; } while (left < right && a[right] > threshold) { right--; } if (left < right) { t = a[left]; a[left] = a[right]; a[right] = t; threshold += 1; } } sum = 0; for (i = 0; i < n; i++) { if (i % 2 == 0) sum += a[i]; } printf("%d ", sum); } (4)下列程序的运行结果是_________________。 #include <stdio.h> #include <string.h> struct Item { int id; int weight; char code[5]; }; main() { struct Item items[]={{101,50,"C01"},{102,30,"A02"},{103,50,"B03"}, {104,20,"D04"}}; int n = 4,i,total,j,swap; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - 1 - i; j++) { swap = 0; if (items[j].weight < items[j+1].weight) { swap = 1;} else if (items[j].weight == items[j+1].weight) { if (strcmp(items[j].code, items[j+1].code) > 0) { swap = 1; } } if (swap) { struct Item t = items[j]; items[j] = items[j+1]; items[j+1] = t; } } } total = 0; for (i = 0; i < n; i++) { total += items[i].id * (i + 1);} printf("%d ", total);} (5)下列程序的运行结果是_________________。 #include <stdio.h> main() { int a[] = {1, 2, 3, 4, 5}; int i = 0; int s = 0; while (i < 5) { s += *(a + i) * (i % 2 == 0 ? 1 : -1); i++; if (s < 0) s = 0; } printf("%d ", s); } (6)下列程序的运行结果是_________________。 #include <stdio.h> int process_matrix(int mat[][4], int rows) { int sum = 0,i,j; for(i = 0; i < rows; i++) { for(j = 0; j < 4; j++) { if(i == 0 || j == 0 || i == rows-1 || j == 3) { sum += mat[i][j]; } else { sum -= mat[i][j]; } } } return sum;} main() { int matrix[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}}; int (*ptr)[4] = matrix; int result = 0,i,j; for(i = 0; i < 2; i++) { result += process_matrix(ptr + i, 2); } printf("%d ", result); for(i = 0; i < 3; i++) { for(j = 0; j < 4; j++) { if(i + j == 3) { printf("%d ", matrix[i][j]); } } } printf(" ");} (7)下列程序的运行结果是_________________。 #include<stdio.h> main() { int i=0; char a[ ]="abm",b[ ]="aqid",c[10]; while(a[i]!='\0'&&b[i]!='\0') { if(a[i]>=b[i]) c[i]=a[i]-32; else c[i]=b[i]-32; i++;} c[i]='\0'; puts(c);} 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是把形参s所指字符串中最右边的n个字符复制到形参t所指字符数组中,形成一个新字符串。若s所指字符串的长度小于n,则将整个字符串复制到形参t所指字符数组中。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> #include <string.h> #define N 80 void fun(__________①___________) {int len,i,j=0; len=strlen(s); if(n>=len) _______②________; else { for(i=________③______;i<=len-1;i++) t[j++]=s[i]; _______④_____; } } main() { char s[N],t[N];int n; printf("Enter a string:"); gets(s); printf("Enter n:"); scanf("%d",&n); fun(s,n,t); printf("The stringt:"); puts(t); } (2)中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,下列程序的功能是,得出这个人在以后的某一天中是“打鱼”还是“晒网”。(4空) #include<stdio.h> int days(struct date day); struct date{ int year; int month; int day; }; int main() { struct date today,term; int yearday,year,day; printf("Enter year/month/day:"); scanf("%d%d%d",&today.year,&today.month,&today.day); term.month=12; term.day=31; for(yearday=0,year=1990;year<today.year;year++) { term.year=year; ________①________; } yearday+=days(today); day=_______②_______; if(day>0&&day<4) printf("he was fishing at that day. "); else printf("He was sleeping at that day. "); } int days(struct date day) { static int day_tab[2][13]= {{0,31,28,31,30,31,30,31,31,30,31,30,31,}, {0,31,29,31,30,31,30,31,31,30,31,30,31,}}; int i,lp; lp=___________③_____________; for(i=1;i<day.month;i++) day.day+=_______④_______; return day.day; } (3)A、B、C、D、E五个人在某天夜里合伙去捕鱼,到第二天凌晨时都疲惫不堪,于是各自找地方睡觉。日上三杆,A第一个醒来,他将鱼分为五份,把多余的一条鱼扔掉,拿走自己的一份。B第二个醒来,也将鱼分为五份,把多余的一条鱼扔掉,保持走自己的一份。C、D、E依次醒来,也按同样的方法拿走鱼。下列程序的功能是求出他们合伙至少捕了多少条鱼。请填空。(4空) #include<stdio.h> int main() { int n,i,x,flag=1; for(n=6;flag;n++) { for(x=n,i=1&&______①_______;i<=5;i++) if((x-1)%5==0) x=_______②_______; else _____③______; if(flag) _______④______; else flag=1; } printf("Total number of fish catched=%d ",n); } (4)在main()函数内输入10个整数到数组中,调用数据交换函数,将数组中最大数与最后一个数交换,最小数与第1个数交换。(3空) #include <stdio.h> void main() { int a[10], i; int *pmax, *pmin; ________①_________ printf("请输入10个整数:"); for(i=0;i<10;i++) scanf("%d",a+i); pmax=a; ________②________; for(i=1;i<10;i++) { if(*pmax<a[i]) pmax=&a[i]; if(*pmin>a[i]) pmin=&a[i]; } swap(pmax,&a[9]); _______③_______; printf("交换后的10个整数依次是: "); for(i=0;i<10;i++) printf("%d\t",a[i]); printf(" "); } void swap(int *px,int *py) { int temp; temp=*px; *px=*py; *py=temp; } (5)从键盘输入若干行字符(最后一行按Enter键时表示输入结束),将它们存入磁盘文件中,再读出这些字符,将其中的大写字母转换成小写字母后写入另一磁盘文件中。(3空) #include <stdio.h> #include <stdlib.h> #include <string.h> void main() { int i=0; FILE *fp,*fp1; char str[100],fname[50],fnamel[50]; printf("请输入两个文件名: "); gets(fname); gets(fnamel); if((fp=fopen(fname,"w+"))==NULL) { printf("不能打开第1个文件,写文件失败! "); exit(0); } if((fp1=fopen(fnamel,"w"))==NULL) { printf("不能打开第2个文件,写文件失败! "); exit(0); } printf("请输入若干行文字: "); while(__________①__________) { fputs(str,fp); fputs(" ",fp); } _________②________; while(fgets(str,100,fp)!=NULL) { for(i=0;_________③__________;i++) if(str[i]>='A' && str[i]<='Z') str[i]=str[i]+32; printf("%s",str); fputs(str,fp1); } fclose(fp); fclose(fp1); } 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)在此程序中,函数fun()的功能是读入一个字符串(长度<20),将该字符串中的所有字符按ASCII值升序排列后输出。例如,若输入"edcba",则应输出"abcde". 请改正程序中的错误,使它能得出正确的结果。以下程序只允许修改两行。 L1 #include <string.h> L2 #include <stdio.h> L3 void fun(char t[]) L4 { L5 char c; L6 int i,j; L7 for(i=strlen(t);i;i--) L8 for(j=0;j<i;j++) L9 if(t[j]<t[j+1]) L10 { L11 c=t[j]; L12 t[j]=t[j+1]; L13 t[j+1]=c; L14 } L15 } L16 main() L17 { L18 char s[81]; L19 printf(" Please enter a char- acter string :"); L20 gets(s); L21 printf(" Before sorting : %s",s); L22 fun(s); L23 printf(" After sorting decend-ingly: %s",s); L24 } ①___________________________________________________ ②___________________________________________________ (2)在此程序中,请编写函数fun(),它的功能是求出能整除x且不是偶数的整数,并将这些整数按从小到大的顺序放在pp所指的数组中,总个数通过形参n返回。以下程序只允许修改三行。 L1 #include <stdio.h> L2 #include <stdlib.h> L3 void fun(int x,int pp[],int *n) L4 { L5 int i,j=0; L6 for(i=1;i<=x;i=i+2) L7 if(x%i==0) L8 pp[j]=i; L9 n=j; L10 } L11 main() L12 { L13 FILE *wf; L14 int x,aa[1000],n,i; L15 system("CLS"); L16 printf(" Please enter an integer number: "); L17 scanf ("%d",&x); L18 fun (x, aa, n); L19 for (i=0;i<n;i++) L20 printf ("%d ",aa[i]); L21 printf (" "); L22 wf=fopen("out.dat","w"); L23 fun(30, aa, &n); L24 for(i=0;i<n;i++) L25 fprintf (wf,"%d ", aa[i]); L26 fclose(wf); L27 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ (3)下列程序的功能是:任意两个正整数的最大公约数和(GCD)和最小公倍数(LCM)。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int a,b,num1,num2,temp; L5 printf("Input a & b:"); L6 scanf("%d%d",&num1,&num2); L7 if(num1<num2) L8 { temp=num1; L9 num1=num2; L10 num2=temp; } L11 a=num1; L12 b=num2; L13 while(b!=0) L14 { temp=a/b; L15 a=b; L16 b=temp; } L17 printf("The GCD of %d and %d is: %d ",num1,num2,a); L18 printf("The LCM of them is: %d ",num1*num2/a); L19 } ①___________________________________________________ ②___________________________________________________ (4)下面程序的功能是:求不超过1000的回文素数。所谓回文素数是指,对一个整数n从左向右和从由向左读其结果值相同且是素数,即称n为回文素数。以下程序只允许修改三行。 L1 #include<stdio.h> L2 int a(int n); L3 int main() L4 { L5 int i,j,t,k,s; L6 printf("Following are palindrome primes not greater than 1000: "); L7 for(i=0;i<=9;++i) L8 for(j=0;j<=9;++j) L9 for(k=0;k<=9;++k) L10 { L11 s=i*100 + j*10 + k; L12 t=i*100 + j*10 + k; L13 if(i == 0 && j==0) L14 { t=t/100; } L15 else if(i ==0) L16 { t = j*10; } L17 if(s>10&& s=t&&a(s)) L18 { printf("%d\t",s); } L19 } L20 return 0; } L21 int a(int n) L22 { int i; L23 for(i=2;i<(n-1)/2;i++) L24 { if(n%i == 0) L25 return 0; } L26 return 1; } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 三、程序设计题(本大题共2小题,合计20分) 1.下列程序的功能是:从链表中删除总和为0的连续节点序列,返回头节点。(每空2分,共10分) 输出结果为: 原始链表: 1 2 -3 3 1 删除和为0的连续节点后: 3 1 #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode *removeZeroSumSublists(struct ListNode* head) { struct ListNode* dummy = NULL; struct ListNode* curr = NULL; struct ListNode* start = NULL,* result; int sum = 0; int found = 0; dummy = ____________①___________; dummy->val = 0; dummy->next = head; start = dummy; while (start != NULL) { curr = _________②_________; sum = 0; found = 0; while (curr != NULL) { sum += curr->val; if (sum == 0) { start->next = _________③_________; found = 1; break; } curr = curr->next; } if (___________④_________) { start = start->next; } } result = dummy->next; free(dummy); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode* head = NULL; struct ListNode* tail = NULL; int i = 0; if (n == 0) { return NULL; } for (i = 0; i < n; i++) { struct ListNode* node = NULL; node = (struct ListNode*)malloc(sizeof(struct ListNode)); node->val = arr[i]; node->next = NULL; if (head == NULL) { head = node; tail = node; } else { tail->next = node; tail = node; } } return head; } void printList(struct ListNode* head) { struct ListNode* curr = head; while (curr != NULL) { printf("%d ", curr->val); curr = curr->next; } printf(" "); } main() { int arr[] = {1, 2, -3, 3, 1}; int n = 5; struct ListNode* head = NULL; struct ListNode* result = NULL; head = createList(arr, n); printf("原始链表: "); printList(head); _____________⑤_____________ printf("删除和为0的连续节点后: "); printList(result); } 2.下列程序的功能是:使用归并排序法对创建的链表进行升序排列。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* merge(____________①___________) { struct ListNode dummy; struct ListNode* tail; dummy.next = NULL; tail = &dummy; while (l1 != NULL && l2 != NULL) { if (l1->val <= l2->val) { tail->next = l1; l1 = l1->next; } else { tail->next = l2; l2 = l2->next; } tail = tail->next; } tail->next = _________②__________; return dummy.next; } struct ListNode* mergeSort(struct ListNode* head) { struct ListNode dummy; struct ListNode* tail; struct ListNode* cur; struct ListNode* left; struct ListNode* right; int length; int size; int count; if (_____________③____________) { return head; } dummy.next = head; length = 0; cur = head; while (cur != NULL) { length++; cur = cur->next; } size = 1; while (__________④_________) { tail = &dummy; cur = dummy.next; while (cur != NULL) { left = cur; count = 1; while (count < size && cur->next != NULL) { cur = cur->next; count++; } right = cur->next; cur->next = NULL; count = 1; cur = right; while (______________⑤______________) { cur = cur->next; count++; } if (cur != NULL) { struct ListNode* nextSegment = cur->next; cur->next = NULL; cur = nextSegment; } tail->next = merge(left, right); while (tail->next != NULL) { tail = tail->next; } } size *= 2; } return dummy.next; } struct ListNode* createList(int arr[], int n) { struct ListNode* head; struct ListNode* tail; int i; struct ListNode* node; head = NULL; tail = NULL; for (i = 0; i < n; i++) { node = (struct ListNode*)malloc(sizeof(struct ListNode)); node->val = arr[i]; node->next = NULL; if (head == NULL) { head = node; tail = node; } else { tail->next = node; tail = node; } } return head; } void printList(struct ListNode* head) { struct ListNode* curr; curr = head; while (curr != NULL) { printf("%d ", curr->val); curr = curr->next; } printf(" "); } main() { int len, i; int* arr; struct ListNode* head; struct ListNode* sorted; printf("请输入链表节点个数:"); scanf("%d", &len); arr = (int*)malloc(len * sizeof(int)); printf("请输入 %d 个整数: ", len); for (i = 0; i < len; i++) { scanf("%d", &arr[i]);} head = createList(arr, len); printf(" 原始链表:"); printList(head); sorted = mergeSort(head); printf("排序后链表:"); printList(sorted); free(arr); } 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $

资源预览图

《C语言程序设计》(高等教育出版社)湖南省(对口升学)计算机类 高频考点冲刺卷(五)
1
《C语言程序设计》(高等教育出版社)湖南省(对口升学)计算机类 高频考点冲刺卷(五)
2
《C语言程序设计》(高等教育出版社)湖南省(对口升学)计算机类 高频考点冲刺卷(五)
3
所属专辑
由于学科网是一个信息分享及获取的平台,不确保部分用户上传资料的 来源及知识产权归属。如您发现相关资料侵犯您的合法权益,请联系学科网,我们核实后将及时进行处理。