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

2026-03-27
| 2份
| 39页
| 80人阅读
| 1人下载

资源信息

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

内容正文:

编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(四 )解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.设有:int a=5,b=6,c=7,d=8,m=2,n=2;执行(m=a>b)&&(n=c>d)后n的值为( ) A.1 B.2 C.3 D.4 【答案】B 【解析】逻辑与运算符 && 具有短路特性,先计算 m=a>b,5>6 结果为假,m 赋值为 0,左侧为假时右侧表达式 n=c>d 不再执行,因此 n 保持初始值 2 不变。 2.以下程序的输出结果是( ) main(){ int i, x[3][3]=(9,8,7,6,5,4,3,2,1),*p=&x[1][1]; for(i=0;i<4;i+=2) printf("%d",p[i]); A.52 B.51 C.53 D.97 【答案】C 【解析】i=0时,输出p[0],也就是x[1][1],输出是5;i=2时,输出p[2],即p[2+0],也就是x[2][0],输出是3。故本题答案为C。 3.以下叙述中错误的是( ) A.算法正确的程序最终一定会结束 B.算法正确的程序可以有零个输出 C.算法正确的程序可以有零个输入 D.算法正确的程序对于相同的输入一定有相同的结果 【答案】B 【解析】算法的5个特性:①有穷性;②确定性;③可行性;④有零个或多个输入;⑤有一个或多个输出。 4.变量math和engl中存放了两门课的成绩。若两门课成绩均在60分以上〈含60),则显示”pass";有一门低于60分则显示"fail",以下不能实现上述功能的程序段是( ) A.if(math<60) if(engl<60) printf("failn"); else printf("pass "); B.if(math<60) printf("fail "); else if(engl>=60) printf("pass "); else printf("fail "); C.if((math<60)||(engl<60)) printf("failn"); else printf("pass "); D.if((math>=60) && (engl>=60)) printf("pass "); else printf("fail "); 【答案】A 【解析】A选项中当两门课都低于60分时,才会显示fail,与题面要求不符,故选项A错误。 5.若有以下程序( ) #include<stdio.h> main() {char a='5',b;a++;printf("%d,%d " ,a-'5'+255, b=a-'5');} A.256,0 B.1,256 C.255,1 D.256,1 【答案】D 【解析】在C语言中,字符串可参与任何整数运算。a进行自增运算后,a=6,a-'5'+255=,6-5+255=256;b=a-'5'=1。故选项D正确。所以本题答案选D。 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include <stdio.h> int func(int n) { static int count = 0; count++; if(n <= 1) { return 1; } return func(n-1) + func(n-2) + count; } main() { int result = func(4); printf("result=%d ", result); result = func(3); printf("result=%d ", result); } 【答案】 result=34 result=30 (2)下列程序的运行结果是_________________。 #include <stdio.h> int fun(int n) { static int k = 0; k += n; return k; } main() { int s = 0,i; for (i = 1; i <= 3; i++) { s += fun(i); } printf("%d ", s); } 【答案】10 (3)下列程序的运行结果是_________________。 #include <stdio.h> main() { char s[] = "HeLLo#WoRLd"; int i = 0; while (s[i]) { if (s[i] == '#') { i++; continue; } if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; else if (s[i] >= 'a' && s[i] <= 'z') s[i] -= 32; i++; } printf("%s ", s); } 【答案】hEllO#wOrlD (4)下列程序的运行结果是_________________。 #include <stdio.h> struct Item { int val; }; main() { int i,j; struct Item items[] = {{30}, {10}, {20}}; struct Item *p[] = {&items[0], &items[1], &items[2]}; for (i = 0; i < 2; i++) { for (j = i + 1; j < 3; j++) { if (p[i]->val > p[j]->val) { struct Item *t = p[i]; p[i] = p[j]; p[j] = t; } } } printf("%d,%d,%d ", p[0]->val, items[0].val, p[2]->val); } 【答案】10,30,30 (5)下列程序的运行结果是_________________。 #include <stdio.h> void convert(int n, int k, char res[]) { int i=0,d,j; char t; do { d = n%k; res[i++] = d<10 ? d+'0' : d-10+'A'; n /= k; } while(n); res[i] = '\0'; for(j=0; j<i/2; j++) { t = res[j]; res[j] = res[i-1-j]; res[i-1-j] = t; } } main() { char s[20]; convert(26, 16, s); printf("%s", s); } 【答案】1A (6)下列程序的运行结果是_________________。 #include <stdio.h> int main() { int a[5]={4,5,6,7,8}; int *b[5],**p; for(p=b;p<b+5;p++) *p=&a[p-b]; for(p=b+4;p>=b;p--) printf("%d",**p); } 【答案】87654 (7)下列程序的运行结果是_________________。 #include <stdio.h> #include <string.h> #define PROCESS(x, y) ((x) = (x) ^ (y), (y) = (x) ^ (y), (x) = (x) ^ (y)) int calculate(int *arr, int n, int (*func)(int, int)) { int result = arr[0],i; for(i = 1; i < n; i++) { result = func(result, arr[i]); } return result; } int add(int a, int b) { return a + b; } int mul(int a, int b) { return a * b; } int main() { int arr[] = {2, 3, 4, 5}; int x = 10, y = 20,sum,product; PROCESS(x, y); printf("x=%d, y=%d ", x, y); sum = calculate(arr, 4, add); product = calculate(arr, 3, mul); printf("sum=%d, product=%d ", sum, product); } 【答案】 x=20, y=10 sum=14, product=24 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是将ss所指字符串中所有下标为奇数的字母转换为大写字母(若该位置上不是字母,则不转换).例如,若输入"abc4Efg",则应输出"aBc4EFg"。(4空) #include <conio.h> #include<stdio.h> #include<string.h> #include<stdlib.h> void fun(char * ss) { int i; for(i=0;_______①________;i++) if(_______②_________) ss[i]=_______③______; } void main() { FILE * wf; char tt[81],s[81]="abc4Efg"; system("CLS"); printf(" Please enter an string within 80 characters: "); gets(tt); printf(" After changing, the string %s",tt); fun(tt); printf(" becomes %s ",tt); wf=fopen("out.dat","w"); fun(s); fprintf (_______④_______); fclose(wf); } 【答案】①ss[i]!='\0' ②i%2==1&&ss[i]>='a'&&ss[i]<='z' ③ss[i]-32 ④wf,"% s",s (2)下列程序中,函数fun的功能是计算下式 S= + + +......+ 直到 ≤ 并把计算结果作为函数值返回。 例如,若形参e的值为1e-3,函数的返回值为2.985678. 请在程序的下划线处填入正确的内容,使程序得出正确的结果。(3空) #include <stdio.h> double fun(double e) { int i; double s,x; s=1.0/4; i=_______①_______; x=1.0; while(x>e){ _______②_________ x=(2.0*i-1)/((_______③_____)*(2.0*i)); s=s+x; } return s; } main() { double e=1e-3; printf(" The result is:%f ",fun(e)); } 【答案】①1 ②i++;或++i;或i=i+1;或i+=1l ③2.0*i (3)程序通过定义学生结构体数组,存储了若干名学生的学号、姓名和3门课的成绩。函数fun的功能是将存放学生数据的结构体数组,按照姓名的字典序(从小到大)排序。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> #include <string.h> struct student { long sno; char name[10]; float score[3]; }; void fun(struct student a[], int n) { ________①________ t; int i, j; for (i=0; i<______②______; i++) for (j=i+1; j<n; j++) if (____________③___________ > 0) { t = a[i]; a[i] = a[j]; a[j] = t; } } main() { struct student s[4]={{10001,"ZhangSan", 95, 80, 88}, {10002,"LiSi", 85, 70, 78},{10003,"CaoKai", 75, 60, 88}, {10004,"FangFang", 90, 82, 87}}; int i, j; printf(" The original data : "); for (j=0; j<4; j++) { printf(" No: %ld Name: %-8s cores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf(" "); } ____________④__________; printf(" The data after sorting : "); for (j=0; j<4; j++) { printf(" No: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf(" "); } getchar(); } 【答案】①struct student ②n-1 ③strcmp(a[i].name,a[j].name) ④fun(s, 4) (4)在下列程序中,函数fun的功能是将形参n所指变量中,各位上为偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新的数,并通过形参指针n传回斤指变量。例如,输入一个数27638496,新的数为739。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> void fun(unsigned long *n) { unsigned long x=0, i; int t; i=1; while(*n) { t=________①________; if(t%2!=____②______) { x=_______③_______; i=i*10; } *n=*n/10; } *n=_______④________; } main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0<n<100000000):"); scanf("%ld",&n); } fun(&n); printf(" The result is: %ld ",n); } 【答案】①*n%10 ②0 ③x+t*i ④x (5)在下列程序中,函数fun()的功能是:将3行4列矩阵x乘以4行3列矩阵y,结果放在3行3列矩阵x y中。矩阵相乘的基本方法是:矩阵xy中行列下标分别为i,j的元素的值,是矩阵x中第i行上4个元素与矩阵y第j列上4个元素对应相乘再相加的和。(3空) #include <stdio.h> #include <string.h> void fun(int a[3][4],int b[4][3],int ab[3][3]) { int j,k,l; for(k=0;k<3;k++) for(l=0;l<3;l++) for(j=0;j<4;j++) _______①_______; } main() { int x[3][4]={{1,0,1,1},{2,1,0,1},{1,2,0,3}}; int y[4][3]={{1,1,1},{0,0,0},{2,1,1},{1,1,3}}; int xy[3][3]={0},i,j; ______②_______; printf("axb=ab:(3,3): "); for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d ",________③________); printf(" "); } } 【答案】①ab[k][l]=ab[k][l]+a[k][j]*b[j][l]; ②fun(x,y,xy) ③xy[i][j] 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)下面程序中,使用折半查找法来查找一个输入的数是否在一个已经排好序的数组中,如果存在就返回所在位置的下标,如果不存在就返回"Not befound"。以下程序只允许修改两行。 L1 #include <stdio.h> L2 #define N 5 L3 int fun(int a[],int m) L4 { L5 int low=0,high=N-1,mid; L6 while(low<=high){ L7 mid=high-low/2; L8 if(m<a[mid]) L9 high=mid-1; L10 else if(m>a[mid]) L11 low=mid+1; L12 else L13 mid=m; L14 } L15 return(-1); L16 } L17 int main() L18 { L19 int i,a[N]={7,9,13,24,67},k,m; L20 scanf("%d",&m); L21 k=fun(a,m); L22 if(k>=0) L23 printf("m=%d,index=%d ",m,k); L24 else L25 printf("Not be found! "); L26 return 0; L27 } ①___________________________________________________ ②___________________________________________________ 【答案】①L7 mid=(high-low)/2; ②L13 return mid; (2)下面程序的功能是:用起泡法对n个整数进行从小到大排序。以下程序只允许修改三行。 L1 #include <stdio.h> L2 void sort(int x,int n) L3 { int i,j,k,t; L4 for(i=0;i<n-1;i++) L5 for(j=0;j<n-i;j++) L6 if(x[j]<x[j+1]) L7 {t=x[j];x[j]=x[j+1];x[j+1]=t;} L8 } L9 main() L10 {int i,n,a[100]; L11 printf("please input the length of the array "); L12 scanf("%d",&n); L13 for(i=0;i<n;i++) L14 scanf("%d",&a[i]); L15 sort(a,n); L16 printf("output the sorted array: "); L17 for(i=0;i<=n-1;i++) L18 printf("%5d",a[i]); L19 printf(" "); L20 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 【答案】①L2 void sort(int x[ ],int n) ②L5 for(j=0;j<n-i-1;j++) ③L6 if(x[j]>x[j+1]) (3)下列程序的功能是:按递增顺序依次列出所有分母为40,分子小于40的最简分数。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int i,num1,num2,temp; L5 printf("The fraction serials with demominator 40 is: "); L6 for(i=1;i<=40;i++) L7 { L8 num1=40; L9 num2=i; L10 while(num2==0) L11 { L12 temp=num1/num2; L13 num1=num2; L14 num2=temp; L15 } L16 if(num1==1) L17 printf("%d/40 ",i);} L18 } ①___________________________________________________ ②___________________________________________________ 【答案】①L10 while(num2!=0) ②L12 temp=num1%num2; (4)将1到9 这九个数字分成三个3位数,分求第一个3位数,正好是第二个3位数的二倍,是第三个3位数的三倍。下面程序的功能是求出这个三位数 。以下程序只允许修改三行。 L1 #include<stdio.h> L2 int ok(int t,int *z); L3 int a[9]; L4 int main() L5 { L6 int m,count=0; L7 for(m=123;m<=333;m++) L8 if(ok(m,a)||ok(2*m,a+3)||ok(3*m,a+6)) L9 printf("No.%d: %d %d %d ",++count,m,2*m,3*m); L10 } L11 int ok(int t,int *z) L12 { L13 int *p1,*p2; L14 for(p1=z;p1<z+3;p1++) L15 { L16 p1=t%10; L17 t/=10; L18 for(p2=a;p2<p1;p2++) L19 if(*p1==0&&*p2==*p1) L20 return 0; L21 } L22 return 1; L23 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 【答案】①L8 if(ok(m,a)&&ok(2*m,a+3)&&ok(3*m,a+6)) ②L16 *p1=t%10; ③L19 if(*p1==0||*p2==*p1) 三、程序设计题(本大题共2小题,合计20分) 1.下列程序的功能是:输入一个排序链表,删除所有含有重复数字的节点,只保留原始链表中没有重复出现的数字。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* deleteDuplicates(struct ListNode* head) { struct ListNode* dummy; struct ListNode* prev; struct ListNode* curr; int duplicate_flag; struct ListNode* temp; struct ListNode* result; dummy = (struct ListNode*)malloc(sizeof(struct ListNode)); dummy->next = head; prev = dummy; curr = head; duplicate_flag = 0; while (______________①______________) { duplicate_flag = 0; while (curr->next != NULL && ____________②__________) { duplicate_flag = 1; temp = curr; curr = curr->next; free(temp); } if (duplicate_flag) { temp = curr; prev->next = ________③________; curr = curr->next; free(temp); } else { prev = prev->next; curr = curr->next; } } result = __________④___________; free(dummy); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode* head; struct ListNode* tail; int i; struct ListNode* node; head = NULL; tail = NULL; if (n == 0) return NULL; for (i = 0; i < n; i++) { node = (struct ListNode*)malloc(sizeof(struct ListNode)); node->val = arr[i]; node->next = NULL; if (___________⑤_________) { 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* result; printf("===== 删除排序链表重复节点 ===== "); 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); result = deleteDuplicates(head); printf("删除重复节点后:"); printList(result); free(arr); } 【答案】①curr != NULL && curr->next != NULL ②curr->val == curr->next->val ③curr->next ④dummy->next ⑤head == NULL 2.下列程序的功能是:创建一个链表,两两交换其中相邻的节点,并返回交换后的链表。不能修改节点中的值,只能进行节点交换。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* swapPairs(struct ListNode* head) { struct ListNode* dummy; struct ListNode* prev; struct ListNode* first; struct ListNode* second; struct ListNode* result; dummy = (struct ListNode*)malloc(sizeof(struct ListNode)); dummy->next = head; prev = dummy; while (______________①_________________) { first = prev->next; second = first->next; first->next = ____________②___________; second->next = first; prev->next = second; prev = _________③_________; } result = dummy->next; free(dummy); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode* head; struct ListNode* tail; int i; struct ListNode* node; head = NULL; tail = NULL; if (n == 0) return NULL; for (i = 0; i < n; i++) { node = _____________④______________; node->val = arr[i]; node->next = NULL; if (head == NULL) { head = node; tail = node; } else { tail->next = node; tail = node; } } return ________⑤_______; } 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* result; printf("===== 链表两两交换程序 ===== "); 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); result = swapPairs(head); printf("两两交换后:"); printList(result); free(arr); } 【答案】①prev->next != NULL && prev->next->next != NULL ②second->next ③first ④(struct ListNode*)malloc(sizeof(struct ListNode)) ⑤head 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $ 编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(四 )解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.设有:int a=5,b=6,c=7,d=8,m=2,n=2;执行(m=a>b)&&(n=c>d)后n的值为( ) A.1 B.2 C.3 D.4 2.以下程序的输出结果是( ) main(){ int i, x[3][3]=(9,8,7,6,5,4,3,2,1),*p=&x[1][1]; for(i=0;i<4;i+=2) printf("%d",p[i]); A.52 B.51 C.53 D.97 3.以下叙述中错误的是( ) A.算法正确的程序最终一定会结束 B.算法正确的程序可以有零个输出 C.算法正确的程序可以有零个输入 D.算法正确的程序对于相同的输入一定有相同的结果 4.变量math和engl中存放了两门课的成绩。若两门课成绩均在60分以上〈含60),则显示”pass";有一门低于60分则显示"fail",以下不能实现上述功能的程序段是( ) A.if(math<60) if(engl<60) printf("failn"); else printf("pass "); B.if(math<60) printf("fail "); else if(engl>=60) printf("pass "); else printf("fail "); C.if((math<60)||(engl<60)) printf("failn"); else printf("pass "); D.if((math>=60) && (engl>=60)) printf("pass "); else printf("fail "); 5.若有以下程序( ) #include<stdio.h> main() {char a='5',b;a++;printf("%d,%d " ,a-'5'+255, b=a-'5');} A.256,0 B.1,256 C.255,1 D.256,1 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include <stdio.h> int func(int n) { static int count = 0; count++; if(n <= 1) { return 1; } return func(n-1) + func(n-2) + count; } main() { int result = func(4); printf("result=%d ", result); result = func(3); printf("result=%d ", result); } (2)下列程序的运行结果是_________________。 #include <stdio.h> int fun(int n) { static int k = 0; k += n; return k; } main() { int s = 0,i; for (i = 1; i <= 3; i++) { s += fun(i); } printf("%d ", s); } (3)下列程序的运行结果是_________________。 #include <stdio.h> main() { char s[] = "HeLLo#WoRLd"; int i = 0; while (s[i]) { if (s[i] == '#') { i++; continue; } if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; else if (s[i] >= 'a' && s[i] <= 'z') s[i] -= 32; i++; } printf("%s ", s); } (4)下列程序的运行结果是_________________。 #include <stdio.h> struct Item { int val; }; main() { int i,j; struct Item items[] = {{30}, {10}, {20}}; struct Item *p[] = {&items[0], &items[1], &items[2]}; for (i = 0; i < 2; i++) { for (j = i + 1; j < 3; j++) { if (p[i]->val > p[j]->val) { struct Item *t = p[i]; p[i] = p[j]; p[j] = t; } } } printf("%d,%d,%d ", p[0]->val, items[0].val, p[2]->val); } (5)下列程序的运行结果是_________________。 #include <stdio.h> void convert(int n, int k, char res[]) { int i=0,d,j; char t; do { d = n%k; res[i++] = d<10 ? d+'0' : d-10+'A'; n /= k; } while(n); res[i] = '\0'; for(j=0; j<i/2; j++) { t = res[j]; res[j] = res[i-1-j]; res[i-1-j] = t; } } main() { char s[20]; convert(26, 16, s); printf("%s", s); } (6)下列程序的运行结果是_________________。 #include <stdio.h> int main() { int a[5]={4,5,6,7,8}; int *b[5],**p; for(p=b;p<b+5;p++) *p=&a[p-b]; for(p=b+4;p>=b;p--) printf("%d",**p); } (7)下列程序的运行结果是_________________。 #include <stdio.h> #include <string.h> #define PROCESS(x, y) ((x) = (x) ^ (y), (y) = (x) ^ (y), (x) = (x) ^ (y)) int calculate(int *arr, int n, int (*func)(int, int)) { int result = arr[0],i; for(i = 1; i < n; i++) { result = func(result, arr[i]); } return result; } int add(int a, int b) { return a + b; } int mul(int a, int b) { return a * b; } int main() { int arr[] = {2, 3, 4, 5}; int x = 10, y = 20,sum,product; PROCESS(x, y); printf("x=%d, y=%d ", x, y); sum = calculate(arr, 4, add); product = calculate(arr, 3, mul); printf("sum=%d, product=%d ", sum, product); } 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是将ss所指字符串中所有下标为奇数的字母转换为大写字母(若该位置上不是字母,则不转换).例如,若输入"abc4Efg",则应输出"aBc4EFg"。(4空) #include <conio.h> #include<stdio.h> #include<string.h> #include<stdlib.h> void fun(char * ss) { int i; for(i=0;_______①________;i++) if(_______②_________) ss[i]=_______③______; } void main() { FILE * wf; char tt[81],s[81]="abc4Efg"; system("CLS"); printf(" Please enter an string within 80 characters: "); gets(tt); printf(" After changing, the string %s",tt); fun(tt); printf(" becomes %s ",tt); wf=fopen("out.dat","w"); fun(s); fprintf (_______④_______); fclose(wf); } (2)下列程序中,函数fun的功能是计算下式 S= + + +......+ 直到 ≤ 并把计算结果作为函数值返回。 例如,若形参e的值为1e-3,函数的返回值为2.985678. 请在程序的下划线处填入正确的内容,使程序得出正确的结果。(3空) #include <stdio.h> double fun(double e) { int i; double s,x; s=1.0/4; i=_______①_______; x=1.0; while(x>e){ _______②_________ x=(2.0*i-1)/((_______③_____)*(2.0*i)); s=s+x; } return s; } main() { double e=1e-3; printf(" The result is:%f ",fun(e)); } (3)程序通过定义学生结构体数组,存储了若干名学生的学号、姓名和3门课的成绩。函数fun的功能是将存放学生数据的结构体数组,按照姓名的字典序(从小到大)排序。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> #include <string.h> struct student { long sno; char name[10]; float score[3]; }; void fun(struct student a[], int n) { ________①________ t; int i, j; for (i=0; i<______②______; i++) for (j=i+1; j<n; j++) if (____________③___________ > 0) { t = a[i]; a[i] = a[j]; a[j] = t; } } main() { struct student s[4]={{10001,"ZhangSan", 95, 80, 88}, {10002,"LiSi", 85, 70, 78},{10003,"CaoKai", 75, 60, 88}, {10004,"FangFang", 90, 82, 87}}; int i, j; printf(" The original data : "); for (j=0; j<4; j++) { printf(" No: %ld Name: %-8s cores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf(" "); } ____________④__________; printf(" The data after sorting : "); for (j=0; j<4; j++) { printf(" No: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf(" "); } getchar(); } (4)在下列程序中,函数fun的功能是将形参n所指变量中,各位上为偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新的数,并通过形参指针n传回斤指变量。例如,输入一个数27638496,新的数为739。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> void fun(unsigned long *n) { unsigned long x=0, i; int t; i=1; while(*n) { t=________①________; if(t%2!=____②______) { x=_______③_______; i=i*10; } *n=*n/10; } *n=_______④________; } main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0<n<100000000):"); scanf("%ld",&n); } fun(&n); printf(" The result is: %ld ",n); } (5)在下列程序中,函数fun()的功能是:将3行4列矩阵x乘以4行3列矩阵y,结果放在3行3列矩阵x y中。矩阵相乘的基本方法是:矩阵xy中行列下标分别为i,j的元素的值,是矩阵x中第i行上4个元素与矩阵y第j列上4个元素对应相乘再相加的和。(3空) #include <stdio.h> #include <string.h> void fun(int a[3][4],int b[4][3],int ab[3][3]) { int j,k,l; for(k=0;k<3;k++) for(l=0;l<3;l++) for(j=0;j<4;j++) _______①_______; } main() { int x[3][4]={{1,0,1,1},{2,1,0,1},{1,2,0,3}}; int y[4][3]={{1,1,1},{0,0,0},{2,1,1},{1,1,3}}; int xy[3][3]={0},i,j; ______②_______; printf("axb=ab:(3,3): "); for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d ",________③________); printf(" "); } } 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)下面程序中,使用折半查找法来查找一个输入的数是否在一个已经排好序的数组中,如果存在就返回所在位置的下标,如果不存在就返回"Not befound"。以下程序只允许修改两行。 L1 #include <stdio.h> L2 #define N 5 L3 int fun(int a[],int m) L4 { L5 int low=0,high=N-1,mid; L6 while(low<=high){ L7 mid=high-low/2; L8 if(m<a[mid]) L9 high=mid-1; L10 else if(m>a[mid]) L11 low=mid+1; L12 else L13 mid=m; L14 } L15 return(-1); L16 } L17 int main() L18 { L19 int i,a[N]={7,9,13,24,67},k,m; L20 scanf("%d",&m); L21 k=fun(a,m); L22 if(k>=0) L23 printf("m=%d,index=%d ",m,k); L24 else L25 printf("Not be found! "); L26 return 0; L27 } ①___________________________________________________ ②___________________________________________________ (2)下面程序的功能是:用起泡法对n个整数进行从小到大排序。以下程序只允许修改三行。 L1 #include <stdio.h> L2 void sort(int x,int n) L3 { int i,j,k,t; L4 for(i=0;i<n-1;i++) L5 for(j=0;j<n-i;j++) L6 if(x[j]<x[j+1]) L7 {t=x[j];x[j]=x[j+1];x[j+1]=t;} L8 } L9 main() L10 {int i,n,a[100]; L11 printf("please input the length of the array "); L12 scanf("%d",&n); L13 for(i=0;i<n;i++) L14 scanf("%d",&a[i]); L15 sort(a,n); L16 printf("output the sorted array: "); L17 for(i=0;i<=n-1;i++) L18 printf("%5d",a[i]); L19 printf(" "); L20 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ (3)下列程序的功能是:按递增顺序依次列出所有分母为40,分子小于40的最简分数。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int i,num1,num2,temp; L5 printf("The fraction serials with demominator 40 is: "); L6 for(i=1;i<=40;i++) L7 { L8 num1=40; L9 num2=i; L10 while(num2==0) L11 { L12 temp=num1/num2; L13 num1=num2; L14 num2=temp; L15 } L16 if(num1==1) L17 printf("%d/40 ",i);} L18 } ①___________________________________________________ ②___________________________________________________ (4)将1到9 这九个数字分成三个3位数,分求第一个3位数,正好是第二个3位数的二倍,是第三个3位数的三倍。下面程序的功能是求出这个三位数 。以下程序只允许修改三行。 L1 #include<stdio.h> L2 int ok(int t,int *z); L3 int a[9]; L4 int main() L5 { L6 int m,count=0; L7 for(m=123;m<=333;m++) L8 if(ok(m,a)||ok(2*m,a+3)||ok(3*m,a+6)) L9 printf("No.%d: %d %d %d ",++count,m,2*m,3*m); L10 } L11 int ok(int t,int *z) L12 { L13 int *p1,*p2; L14 for(p1=z;p1<z+3;p1++) L15 { L16 p1=t%10; L17 t/=10; L18 for(p2=a;p2<p1;p2++) L19 if(*p1==0&&*p2==*p1) L20 return 0; L21 } L22 return 1; L23 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 三、程序设计题(本大题共2小题,合计20分) 1.下列程序的功能是:输入一个排序链表,删除所有含有重复数字的节点,只保留原始链表中没有重复出现的数字。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* deleteDuplicates(struct ListNode* head) { struct ListNode* dummy; struct ListNode* prev; struct ListNode* curr; int duplicate_flag; struct ListNode* temp; struct ListNode* result; dummy = (struct ListNode*)malloc(sizeof(struct ListNode)); dummy->next = head; prev = dummy; curr = head; duplicate_flag = 0; while (______________①______________) { duplicate_flag = 0; while (curr->next != NULL && ____________②__________) { duplicate_flag = 1; temp = curr; curr = curr->next; free(temp); } if (duplicate_flag) { temp = curr; prev->next = ________③________; curr = curr->next; free(temp); } else { prev = prev->next; curr = curr->next; } } result = __________④___________; free(dummy); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode* head; struct ListNode* tail; int i; struct ListNode* node; head = NULL; tail = NULL; if (n == 0) return NULL; for (i = 0; i < n; i++) { node = (struct ListNode*)malloc(sizeof(struct ListNode)); node->val = arr[i]; node->next = NULL; if (___________⑤_________) { 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* result; printf("===== 删除排序链表重复节点 ===== "); 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); result = deleteDuplicates(head); printf("删除重复节点后:"); printList(result); free(arr); } 2.下列程序的功能是:创建一个链表,两两交换其中相邻的节点,并返回交换后的链表。不能修改节点中的值,只能进行节点交换。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* swapPairs(struct ListNode* head) { struct ListNode* dummy; struct ListNode* prev; struct ListNode* first; struct ListNode* second; struct ListNode* result; dummy = (struct ListNode*)malloc(sizeof(struct ListNode)); dummy->next = head; prev = dummy; while (______________①_________________) { first = prev->next; second = first->next; first->next = ____________②___________; second->next = first; prev->next = second; prev = _________③_________; } result = dummy->next; free(dummy); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode* head; struct ListNode* tail; int i; struct ListNode* node; head = NULL; tail = NULL; if (n == 0) return NULL; for (i = 0; i < n; i++) { node = _____________④______________; node->val = arr[i]; node->next = NULL; if (head == NULL) { head = node; tail = node; } else { tail->next = node; tail = node; } } return ________⑤_______; } 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* result; printf("===== 链表两两交换程序 ===== "); 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); result = swapPairs(head); printf("两两交换后:"); printList(result); free(arr); } 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $

资源预览图

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