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

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

资源信息

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

内容正文:

编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(七)解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.设有变量定义,并已赋确定值:char w;int x;float y;double z;则表达式w-y*x+z所求得的值的数据类型为( ) A.char B.int C.float D.double 2.设有以下程序代码,则程序运行时不能输入10,20的语句是( ) #include<stdio.h> struct link { int data;struct link *next;} main() { struct link *h,a,b; h=&a; a.data=10;a.next=&b;b.data=20; } A.printf("%d,%d ",a.data,(*a.next).data); B.printf("%d,%d ",h->data,a.next.data); C.printf("%d,%d ",h->data,(*a.next).data); D.printf("%d,%d ",a.data,a.next->data); 3.设有定义:float a=5,b=a+=5/2;,则执行语句:printf("%f",b);后的输出结果是( ) A.7.500000 B.7 C.5.000000 D.7.000000 4.设有以下程序段,运行后该程序的输出结果是( ) int a,b,c;a=10; b=50; c=30; if(a>b) a=b,b=c;c=a; printf("a=%d b=%d c=%d " ,a, b,c); A.a=10 b=50 c=10 B.a=10 b=50 c=30 C.a=10 b=30 c=10 D.a=50 b=30 c=50 5.若有定义语句:double x[5]={1.0.2.0.3.0.4.0.5.0},*p=x;则下列选项中错误引用x数组元素的是( ) A.*p B.x[5] C.*(p+1) D.*x 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include <stdio.h> main() { int a[5]={1,3,2,4,5}; int n=0,m=4,i; for(i=0;i<5;i++) { if(a[i]%2) a[n++]=a[i]; else a[m--]=a[i]; } for(i=0;i<n;i++) printf("%d",a[m--]); } (2)下列程序的运行结果是_________________。 #include <stdio.h> main() { int i, j, k = 0,flag; for (i = 1; i <= 4; i++) { flag = 0; for (j = 1; j <= i; j++) { if ((i * j) % 3 == 0) { flag = 1; break; } } if (flag) k += i; else k -= i; } printf("%d ", k); } (3)下列程序的运行结果是_________________。 #include <stdio.h> main() { char *s[] = {"ABC", "DEF", "GHI"}; char **p = s; printf("%c,%c,", *(*p + 1), *(*(p + 1) + 2)); p++; printf("%c", **p + 2); } (4)下列程序的运行结果是_________________。 #include <stdio.h> struct S { int n; int a[20];}; void f(struct S *p) { int i,j,t; for(i=0;i<p->n-1;i++) for(j=i+1;j<p->n;j++) if(p->a[i]>p->a[j]) { t=p->a[i]; p->a[i]=p->a[j]; p->a[j]=t; } } main() { int i; struct S s={10,{2,3,1,6,8,7,5,4,10,9}}; f(&s); for(i=0;i<s.n;i++) printf("%d,",s.a[i]); } (5)下列程序的运行结果是_________________。 #include<stdio.h> int f(char *s,char *t) { int n=0,num=0; char *p,*r; while(*s) { p=s; r=t; while(*r) if(*r==*p) {r++;p++;} else break; if(*r=='\0') num+=1; n++;s++; } return num;} main() {printf("the result is %d ",f("aabdabc","ab")); } (6)下列程序的运行结果是_________________。 #include <stdio.h> int calc(int a, int b) { int r = 0,i,j,prime; for(i=a; i<=b; i++) { prime = 1; for(j=2; j*j<=i; j++) { if(i%j == 0) { prime=0; break; } } if(prime && i>1) r += i; } return r; } main() { printf("%d", calc(10,20)); } (7)下列程序的运行结果是_________________。 #include <stdio.h> int process(int *x, int n) { int r = 1,i; for(i = 0; i < n; i++) { if(i % 3 == 0) r *= x[i]; else if(i % 3 == 1) r += x[i]; else r -= x[i]; } return r; } main() { int arr[6] = {2, 3, 4, 1, 5, 6}; int *p = arr, *q = arr + 3; int total = 0,i,val,temp; for(i = 0; i < 2; i++) { val = process(p + i, 4 - i); total += val; printf("Cycle %d: val=%d, total=%d ", i, val, total); temp = *(p + i); *(p + i) = *(q - i - 1); *(q - i - 1) = temp; } printf("Final: %d ", total);} 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是计算下式前n项的和,并将结果作为函数值返回。 s=-+-…+ 例如,当形参n的值为10时,函数返回 -0.204491. 请在程序的下划线处填人正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> double fun(int n) { int i, k; double s,t; s=0; _______①______; for(i=1;i<=n;i++) { t=________②_________; s=__________③__________/(t*t); k=k*______④____; } return s; } main() { int n=-1; while(n<0) { printf("Please input(n>0):"); scanf("%d",&n);} printf(" The result is:%f ",fun(n)); } (2)要发就发"1898要发就发"。请将不超过1993的所有素数从小到大排成第一行,第二行上的每个素数都等于它右肩上的素数之差。编程求出:第二行数中是否存在这样的若干个连续的整数,它们的和恰好是1898? 如果存在的话,又有几种这样的情况?请填空。(5空) 第一行;2 3 5 7 11 13 17......1979 1987 1993 第二行:1 2 2 4 2 4......8 6 #include<stdio.h> #include<math.h> #define NUM 400 int number[NUM]; int fflag(int i){ int j; if(i <= 1) return 0; if(i == 2) return 1; if(i % 2 == 0) return 0; for(j = 3; j <= sqrt(i) + 1; j += 2) if(_______①_______) return 0; __________②__________; } main(){ int i, j, count = 0; int index = 0; number[index++] = 2; for(i = 3; i <= 1993; _______③_______){ if(_______④_______){ number[index++] = i; } } printf("满足条件的连续差值和为1898的情况: "); for(i = 0; i < index; i++){ for(j = i + 1; j < index; j++){ if(_____________⑤___________){ count++; printf("第%d种:素数 %d 到 %d,差值和=1898 ", count, number[i], number[j]); } } } printf(" 总计有 %d 种符合条件的情况 ", count); } (3)下列程序的功能是从键盘上输入一个五位整数,对此整数中的五个数值(即万位,千位,百位,十位,个位上的数字)进行从大到小的排序,形成一个新的五位整数,并输出这个整数。例如,输入41325,则输出54321。请补全代码。(4空) #include <stdio.h> #include <math.h> main() { void fun(int a[ ]); long int x,y; int i,a[5]; scanf("%ld",&x); if(__________①__________) { printf("This data is error."); } for(i=0;i<5;++i) { a[i]=x%10; x=x/10; } fun(a); y=0; for(i=0;i<5;++i) y=___________②___________; printf("%1d",y); } void fun(int a[]) { int i,j,k; for(i=0;i<5;++i) for(j=i;j<5;++j) if(_________③_______) {___________④__________; a[i]=a[j]; a[j]=k; } } (4)下列程序的功能是:函数fun的功能是:根据形参c中存储的整数序列,分别统计偶数元素和奇数元素的个数,将统计结果以结构变量返回主函数,结构变量的类型由程序中定义的structpair给出,它包含两个整数变量成员,依次对应偶数个数与奇数个数之和、偶数个数与奇数个数之差。形参d中存储的是序列的长度。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(3空) #include <stdio.h> struct pair { int n1, n2; }; struct pair fun(int* c, int d) { int i; _______①______; p.n1 = p.n2 = 0; for (i=0; i<d; ____②____) { if (c[i] % 2 == 0) p.n1++; else ____③____; } p.n1 = p.n1 + p.n2; p.n2 = p.n1 - p.n2 - p.n2; return p; } int main( ) { int i, c[100], d; struct pair p; scanf("%d", &d); for (i = 0; i < d; i++) scanf("%d", &(c[i])); p = fun(c, d); printf("n1=%d,n2=%d", p.n1, p.n2); return 0; } (5)函数fun的功能是在数组中找出两科成绩之和最高的学生并返回其在数组中的下标。对所给函数int fun(STU*d,int n),主函数传给形参d的是学生数组名,而传给形参n的是该数组中学生的个数。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(2空) #include<stdio.h> typedef struct stu { char ID[30]; char name[20]; int score[2]; } STU; int fun(STU *d,int n) { int i,m; ______①_______; for(i=1;i<n;i++) if(d[i].score[0]+d[i].score[1]>_________②_________) m=i; return m; } void main() { STU a[10]={ "2016500301","李清水",83,92, "2016500336","刘世才",85,94, "2016500371","王子晨",88,88}; int i,n=3; i=fun(a,n); printf("%30s%20s%4d%4d",a[i].ID,a[i].name,a[i].score[0],a[i].score[1]); printf(" "); } 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)在此程序中,函数fun()的功能是首先把b所指字符串中的字符按逆序存放,然后将a所指字符串中的字符和b所指字符串中的字符,按排列的顺序交叉合并到e所指数组中,较长字符串的剩余字符接在c所指的数组的尾部。 例如,当a所指字符串中的内容为"abedefg",b所指字符串中的内容为"1234"时,c所指数组中的内容应为"a4b3c2d1efg"。请改正程序中的错误,使它能得出正确的结果。以下程序只允许修改两行。 L1 #include <stdio.h> L2 #include <string.h> L3 void fun(char *a, char *b, char*c) L4 { int i,j; char ch; L5 i=0;j= strlen(b)-1; L6 while(i>j) L7 {ch =b[i];b[i]=b[j]; L8 b[j]=ch; L9 i++;j--; L10 } L11 while (*a&&*b) L12 { L13 if (*a) L14 { *c= *a; L15 c++;a++;} L16 if (*b) L17 { *c= *b; L18 c++;b++;} L19 } L20 *c=0; L21 } L22 main() L23 { L24 char s1[100],s2[100],t[200]; L25 printf(" Enter sl string:"); L26 scanf("%s",s1); L27 printf(" Enter s2 string:"); L28 scanf("%s",s2); L29 fun( s1, s2,t); L30 printf(" The result is:%s ",t); L31 } ①___________________________________________________ ②___________________________________________________ (2)函数fun的功能是:对于长整数n中的各个位置上的数值,分别统计出为0和为1的个数,并传递回主函数输出。请改正函数fun中指定部位的错误,使它能得出正确的结果。以下程序只允许修改三行。 L1 #include <stdio.h> L2 void fun(long n,int *c0,int *c1) L3 { int k; L4 *c0=*c1=1; L5 do L6 { L7 k= n/10; L8 if(k==0) (*c0)++; L9 if(k==1) (*c1)++; L10 n=n-10; L11 } L12 while (n); L13 } L14 main() L15 { long n; int c0,c1; L16 printf("input n:"); L17 scanf("%ld",&n); L18 fun(n,&c0,&c1); L19 printf("c0=%d,c1=%d ",c0,c1); L20 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ (3)如果一个正整数等于其各个数字的立方和,则称该数为阿姆斯特朗数(亦称为自恋性数)。如 407=43+03+73就是一个阿姆斯特朗数。下列程序的功能是求1000以内的所有阿姆斯特朗数。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int i,t,k,a[3]; L5 printf("There are follwing Armstrong number smaller than 1000: "); L6 for(i=2;i<1000;i++) L7 { L8 for(t=0,k=1000;k>=10;t++) L9 { L10 a[t]=i%k/k/10; L11 k%=10; L12 } L13 if(a[0]*a[0]*a[0]+a[1]*a[1]*a[1]+a[2]*a[2]*a[2]==i) L14 printf("%5d",i); L15 } L16 printf(" "); L17 } ①___________________________________________________ ②___________________________________________________ (4)下列给定程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为"abcdabfab",t所指字符串的内容为"ab",则函数返回整数3。请改正程序中的错误,使它能得出正确的结果。。以下程序只允许修改三行。 #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> L1 int fun(char s, char t) L2 { L3 int n; L4 char *p,*r; L5 n=0; L6 while(*s) L7 { L8 p=s; L9 r=t; L10 while(*r) L11 if(*r==*p){r++;p++} L12 else break; L13 if(r=='\0') L14 n++; L15 s++; L16 } L17 return n; L18 } L19 void main() L20 { L21 char s[100],t[100]; int m; L22 system("CLS"); L23 printf(" Please enter strings:"); L24 scanf("%s",s); L25 printf(" Please enter substrings:"); L26 scanf("%s",t); L27 m=fun(s,t); L28 printf(" The result is:m=%d ", m); L29 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 三、程序设计题(本大题共2小题,合计20分) 1.在下列程序中,给出两个非空的链表用来表示两个非负的整数。其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只存储一位数字。将两个数相加,并以相同形式返回一个表示和的链表。程序运行结果如下图所示,请你依据题意补充程序。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) { struct ListNode dummy; struct ListNode* tail; int carry; int sum; struct ListNode* newNode; tail = &dummy; dummy.next = NULL; carry = 0; while (_____________①____________) { sum = carry; if (l1 != NULL) { ____________②____________; l1 = l1->next; } if (l2 != NULL) { sum += l2->val; l2 = l2->next; } carry = sum / 10; newNode = ______________③________________; newNode->val = __________④________; newNode->next = NULL; tail->next = newNode; tail = newNode; } 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 n1, n2; int i; int* arr1; int* arr2; struct ListNode* l1; struct ListNode* l2; struct ListNode* result; printf("请输入第一个链表的节点个数:"); scanf("%d", &n1); arr1 = ____________⑤_____________; printf("请输入第一个链表的 %d 个数字(逆序存储,如 342 输入:2 4 3): ", n1); for (i = 0; i < n1; i++) { scanf("%d", &arr1[i]); } printf(" 请输入第二个链表的节点个数:"); scanf("%d", &n2); arr2 = (int*)malloc(n2 * sizeof(int)); printf("请输入第二个链表的 %d 个数字(逆序存储): ", n2); for (i = 0; i < n2; i++) { scanf("%d", &arr2[i]); } l1 = createList(arr1, n1); l2 = createList(arr2, n2); printf(" 链表 1:"); printList(l1); printf("链表 2:"); printList(l2); result = addTwoNumbers(l1, l2); printf(" 相加结果(逆序):"); printList(result); free(arr1); free(arr2); } 2.下列程序的功能是:给定一个链表,删除链表的倒数第N个节点,并返回链表的头节点。(每空2分,共10分) 输出结果: 原链表: 1 2 3 4 5 删除倒数第 2 个节点后: 1 2 3 5 #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* removeNthFromEnd(struct ListNode* head, int n) { struct ListNode dummy; struct ListNode* first; struct ListNode* second; struct ListNode* temp; int i; dummy.next = head; first = &dummy; second = &dummy; for (i = 0; i <= n; i++) { first = _____________①____________; } while (first != NULL) { first = first->next; __________②__________; } temp = __________③___________; second->next = temp->next; free(temp); 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 = node; } } return head; } void printList(struct ListNode* head) { struct ListNode* curr; curr = head; while (curr != NULL) { printf("%d ", curr->val); ____________⑤______________; } printf(" "); } main() { int arr[] = {1,2,3,4,5}; int len; int n; struct ListNode* head; struct ListNode* newHead; len = sizeof(arr) / sizeof(arr[0]); head = createList(arr, len); printf("原链表: "); printList(head); n = 2; newHead = removeNthFromEnd(head, n); printf("删除倒数第 %d 个节点后: ", n); printList(newHead); } 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $ 编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(七)解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.设有变量定义,并已赋确定值:char w;int x;float y;double z;则表达式w-y*x+z所求得的值的数据类型为( ) A.char B.int C.float D.double 【答案】D 【解析】C 语言表达式运算遵循类型提升规则,运算时会向精度更高的类型转换,该表达式中包含最高精度的 double 类型变量 z,运算过程中所有操作数最终都会提升为 double 类型,因此表达式结果类型为 double。 2.设有以下程序代码,则程序运行时不能输入10,20的语句是( ) #include<stdio.h> struct link { int data;struct link *next;} main() { struct link *h,a,b; h=&a; a.data=10;a.next=&b;b.data=20; } A.printf("%d,%d ",a.data,(*a.next).data); B.printf("%d,%d ",h->data,a.next.data); C.printf("%d,%d ",h->data,(*a.next).data); D.printf("%d,%d ",a.data,a.next->data); 【答案】B 【解析】选项 B 中 a.next.data 错误:a.next 是指针,应写为 a.next->data 或 (*a.next).data。 3.设有定义:float a=5,b=a+=5/2;,则执行语句:printf("%f",b);后的输出结果是( ) A.7.500000 B.7 C.5.000000 D.7.000000 【答案】D 【解析】5/2看作两个整数相除,结果为2,a+=2的结果为7.000000,再赋值给b。故选D。 4.设有以下程序段,运行后该程序的输出结果是( ) int a,b,c;a=10; b=50; c=30; if(a>b) a=b,b=c;c=a; printf("a=%d b=%d c=%d " ,a, b,c); A.a=10 b=50 c=10 B.a=10 b=50 c=30 C.a=10 b=30 c=10 D.a=50 b=30 c=50 【答案】A 【解析】本题if条件表达式'a>b"的值为0,所以不执行其后的if语句'a=b,b=c;”,直接执行下一条语句"c=a;”,故c变量的值为10,所以输出结果为“a=10 b=50 c=10”。故本题答案为A 5.若有定义语句:double x[5]={1.0.2.0.3.0.4.0.5.0},*p=x;则下列选项中错误引用x数组元素的是( ) A.*p B.x[5] C.*(p+1) D.*x 【答案】B 【解析】本题定义了一个有5个数组元素的一维数组x和指针变量p,且将x的首地址(即x[0]的地址)赋给了指针变量p,即p指向了x数组的第0号元素,所以*p的值为x[0]的值,选项A的引用正确;由于p+1就是x[1]的地址,所以*(p+1)所指向的数组元素为x[1],故选项C的引用正确;由于x就是数组x的首地址,所以*x即对x[0]的引用,所以选项D引用正确;由于数组最大下标是元素个数减一,所以选项B的引用越界。故本题答案为B 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include <stdio.h> main() { int a[5]={1,3,2,4,5}; int n=0,m=4,i; for(i=0;i<5;i++) { if(a[i]%2) a[n++]=a[i]; else a[m--]=a[i]; } for(i=0;i<n;i++) printf("%d",a[m--]); } 【答案】31 (2)下列程序的运行结果是_________________。 #include <stdio.h> main() { int i, j, k = 0,flag; for (i = 1; i <= 4; i++) { flag = 0; for (j = 1; j <= i; j++) { if ((i * j) % 3 == 0) { flag = 1; break; } } if (flag) k += i; else k -= i; } printf("%d ", k); } 【答案】4 (3)下列程序的运行结果是_________________。 #include <stdio.h> main() { char *s[] = {"ABC", "DEF", "GHI"}; char **p = s; printf("%c,%c,", *(*p + 1), *(*(p + 1) + 2)); p++; printf("%c", **p + 2); } 【答案】B,F,F (4)下列程序的运行结果是_________________。 #include <stdio.h> struct S { int n; int a[20];}; void f(struct S *p) { int i,j,t; for(i=0;i<p->n-1;i++) for(j=i+1;j<p->n;j++) if(p->a[i]>p->a[j]) { t=p->a[i]; p->a[i]=p->a[j]; p->a[j]=t; } } main() { int i; struct S s={10,{2,3,1,6,8,7,5,4,10,9}}; f(&s); for(i=0;i<s.n;i++) printf("%d,",s.a[i]); } 【答案】1,2,3,4,5,6,7,8,9,10, (5)下列程序的运行结果是_________________。 #include<stdio.h> int f(char *s,char *t) { int n=0,num=0; char *p,*r; while(*s) { p=s; r=t; while(*r) if(*r==*p) {r++;p++;} else break; if(*r=='\0') num+=1; n++;s++; } return num;} main() {printf("the result is %d ",f("aabdabc","ab")); } 【答案】the result is 2 (6)下列程序的运行结果是_________________。 #include <stdio.h> int calc(int a, int b) { int r = 0,i,j,prime; for(i=a; i<=b; i++) { prime = 1; for(j=2; j*j<=i; j++) { if(i%j == 0) { prime=0; break; } } if(prime && i>1) r += i; } return r; } main() { printf("%d", calc(10,20)); } 【答案】60 (7)下列程序的运行结果是_________________。 #include <stdio.h> int process(int *x, int n) { int r = 1,i; for(i = 0; i < n; i++) { if(i % 3 == 0) r *= x[i]; else if(i % 3 == 1) r += x[i]; else r -= x[i]; } return r; } main() { int arr[6] = {2, 3, 4, 1, 5, 6}; int *p = arr, *q = arr + 3; int total = 0,i,val,temp; for(i = 0; i < 2; i++) { val = process(p + i, 4 - i); total += val; printf("Cycle %d: val=%d, total=%d ", i, val, total); temp = *(p + i); *(p + i) = *(q - i - 1); *(q - i - 1) = temp; } printf("Final: %d ", total);} 【答案】 Cycle 0: val=1, total=1 Cycle 1: val=4, total=5 Final: 5 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是计算下式前n项的和,并将结果作为函数值返回。 s=-+-…+ 例如,当形参n的值为10时,函数返回 -0.204491. 请在程序的下划线处填人正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> double fun(int n) { int i, k; double s,t; s=0; _______①______; for(i=1;i<=n;i++) { t=________②_________; s=__________③__________/(t*t); k=k*______④____; } return s; } main() { int n=-1; while(n<0) { printf("Please input(n>0):"); scanf("%d",&n);} printf(" The result is:%f ",fun(n)); } 【答案】①k=1 ②2*i ③s+k*(2*i-1)*(2*i+1) ④-1 (2)要发就发"1898要发就发"。请将不超过1993的所有素数从小到大排成第一行,第二行上的每个素数都等于它右肩上的素数之差。编程求出:第二行数中是否存在这样的若干个连续的整数,它们的和恰好是1898? 如果存在的话,又有几种这样的情况?请填空。(5空) 第一行;2 3 5 7 11 13 17......1979 1987 1993 第二行:1 2 2 4 2 4......8 6 #include<stdio.h> #include<math.h> #define NUM 400 int number[NUM]; int fflag(int i){ int j; if(i <= 1) return 0; if(i == 2) return 1; if(i % 2 == 0) return 0; for(j = 3; j <= sqrt(i) + 1; j += 2) if(_______①_______) return 0; __________②__________; } main(){ int i, j, count = 0; int index = 0; number[index++] = 2; for(i = 3; i <= 1993; _______③_______){ if(_______④_______){ number[index++] = i; } } printf("满足条件的连续差值和为1898的情况: "); for(i = 0; i < index; i++){ for(j = i + 1; j < index; j++){ if(_____________⑤___________){ count++; printf("第%d种:素数 %d 到 %d,差值和=1898 ", count, number[i], number[j]); } } } printf(" 总计有 %d 种符合条件的情况 ", count); } 【答案】①i%j==0或!(i%j) ②return 1 ③i += 2 ④fflag(i)或fflag(i)==1 ⑤number[j] - number[i] == 1898 (3)下列程序的功能是从键盘上输入一个五位整数,对此整数中的五个数值(即万位,千位,百位,十位,个位上的数字)进行从大到小的排序,形成一个新的五位整数,并输出这个整数。例如,输入41325,则输出54321。请补全代码。(4空) #include <stdio.h> #include <math.h> main() { void fun(int a[ ]); long int x,y; int i,a[5]; scanf("%ld",&x); if(__________①__________) { printf("This data is error."); } for(i=0;i<5;++i) { a[i]=x%10; x=x/10; } fun(a); y=0; for(i=0;i<5;++i) y=___________②___________; printf("%1d",y); } void fun(int a[]) { int i,j,k; for(i=0;i<5;++i) for(j=i;j<5;++j) if(_________③_______) {___________④__________; a[i]=a[j]; a[j]=k; } } 【答案】①(x<10000)||(x>99999) ②y*10+a[i] ③a[i]<a[j] ④k=a[i] (4)下列程序的功能是:函数fun的功能是:根据形参c中存储的整数序列,分别统计偶数元素和奇数元素的个数,将统计结果以结构变量返回主函数,结构变量的类型由程序中定义的structpair给出,它包含两个整数变量成员,依次对应偶数个数与奇数个数之和、偶数个数与奇数个数之差。形参d中存储的是序列的长度。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(3空) #include <stdio.h> struct pair { int n1, n2; }; struct pair fun(int* c, int d) { int i; _______①______; p.n1 = p.n2 = 0; for (i=0; i<d; ____②____) { if (c[i] % 2 == 0) p.n1++; else ____③____; } p.n1 = p.n1 + p.n2; p.n2 = p.n1 - p.n2 - p.n2; return p; } int main( ) { int i, c[100], d; struct pair p; scanf("%d", &d); for (i = 0; i < d; i++) scanf("%d", &(c[i])); p = fun(c, d); printf("n1=%d,n2=%d", p.n1, p.n2); return 0; } 【答案】①struct pair p; ②i++ ③p.n2++ (5)函数fun的功能是在数组中找出两科成绩之和最高的学生并返回其在数组中的下标。对所给函数int fun(STU*d,int n),主函数传给形参d的是学生数组名,而传给形参n的是该数组中学生的个数。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(2空) #include<stdio.h> typedef struct stu { char ID[30]; char name[20]; int score[2]; } STU; int fun(STU *d,int n) { int i,m; ______①_______; for(i=1;i<n;i++) if(d[i].score[0]+d[i].score[1]>_________②_________) m=i; return m; } void main() { STU a[10]={ "2016500301","李清水",83,92, "2016500336","刘世才",85,94, "2016500371","王子晨",88,88}; int i,n=3; i=fun(a,n); printf("%30s%20s%4d%4d",a[i].ID,a[i].name,a[i].score[0],a[i].score[1]); printf(" "); } 【答案】①m=0 ②d[m].score[0]+d[m].score[1] 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)在此程序中,函数fun()的功能是首先把b所指字符串中的字符按逆序存放,然后将a所指字符串中的字符和b所指字符串中的字符,按排列的顺序交叉合并到e所指数组中,较长字符串的剩余字符接在c所指的数组的尾部。 例如,当a所指字符串中的内容为"abedefg",b所指字符串中的内容为"1234"时,c所指数组中的内容应为"a4b3c2d1efg"。请改正程序中的错误,使它能得出正确的结果。以下程序只允许修改两行。 L1 #include <stdio.h> L2 #include <string.h> L3 void fun(char *a, char *b, char*c) L4 { int i,j; char ch; L5 i=0;j= strlen(b)-1; L6 while(i>j) L7 {ch =b[i];b[i]=b[j]; L8 b[j]=ch; L9 i++;j--; L10 } L11 while (*a&&*b) L12 { L13 if (*a) L14 { *c= *a; L15 c++;a++;} L16 if (*b) L17 { *c= *b; L18 c++;b++;} L19 } L20 *c=0; L21 } L22 main() L23 { L24 char s1[100],s2[100],t[200]; L25 printf(" Enter sl string:"); L26 scanf("%s",s1); L27 printf(" Enter s2 string:"); L28 scanf("%s",s2); L29 fun( s1, s2,t); L30 printf(" The result is:%s ",t); L31 } ①___________________________________________________ ②___________________________________________________ 【答案】①L6 while(i<j) ②L11 while (*a||*b) (2)函数fun的功能是:对于长整数n中的各个位置上的数值,分别统计出为0和为1的个数,并传递回主函数输出。请改正函数fun中指定部位的错误,使它能得出正确的结果。以下程序只允许修改三行。 L1 #include <stdio.h> L2 void fun(long n,int *c0,int *c1) L3 { int k; L4 *c0=*c1=1; L5 do L6 { L7 k= n/10; L8 if(k==0) (*c0)++; L9 if(k==1) (*c1)++; L10 n=n-10; L11 } L12 while (n); L13 } L14 main() L15 { long n; int c0,c1; L16 printf("input n:"); L17 scanf("%ld",&n); L18 fun(n,&c0,&c1); L19 printf("c0=%d,c1=%d ",c0,c1); L20 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 【答案】①L4 *c0=*c1=0; ②L7 k= n%10; ③L10 n=n/10; (3)如果一个正整数等于其各个数字的立方和,则称该数为阿姆斯特朗数(亦称为自恋性数)。如 407=43+03+73就是一个阿姆斯特朗数。下列程序的功能是求1000以内的所有阿姆斯特朗数。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int i,t,k,a[3]; L5 printf("There are follwing Armstrong number smaller than 1000: "); L6 for(i=2;i<1000;i++) L7 { L8 for(t=0,k=1000;k>=10;t++) L9 { L10 a[t]=i%k/k/10; L11 k%=10; L12 } L13 if(a[0]*a[0]*a[0]+a[1]*a[1]*a[1]+a[2]*a[2]*a[2]==i) L14 printf("%5d",i); L15 } L16 printf(" "); L17 } ①___________________________________________________ ②___________________________________________________ 【答案】①L10 a[t]=(i%k)/(k/10); ②L11 k/=10; (4)下列给定程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为"abcdabfab",t所指字符串的内容为"ab",则函数返回整数3。请改正程序中的错误,使它能得出正确的结果。。以下程序只允许修改三行。 #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> L1 int fun(char s, char t) L2 { L3 int n; L4 char *p,*r; L5 n=0; L6 while(*s) L7 { L8 p=s; L9 r=t; L10 while(*r) L11 if(*r==*p){r++;p++} L12 else break; L13 if(r=='\0') L14 n++; L15 s++; L16 } L17 return n; L18 } L19 void main() L20 { L21 char s[100],t[100]; int m; L22 system("CLS"); L23 printf(" Please enter strings:"); L24 scanf("%s",s); L25 printf(" Please enter substrings:"); L26 scanf("%s",t); L27 m=fun(s,t); L28 printf(" The result is:m=%d ", m); L29 } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ 【答案】①L1 int fun(char *s, char *t) ②L11 if(*r==*p){r++;p++;} ③L13 if(*r=='\0') 三、程序设计题(本大题共2小题,合计20分) 1.在下列程序中,给出两个非空的链表用来表示两个非负的整数。其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只存储一位数字。将两个数相加,并以相同形式返回一个表示和的链表。程序运行结果如下图所示,请你依据题意补充程序。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) { struct ListNode dummy; struct ListNode* tail; int carry; int sum; struct ListNode* newNode; tail = &dummy; dummy.next = NULL; carry = 0; while (_____________①____________) { sum = carry; if (l1 != NULL) { ____________②____________; l1 = l1->next; } if (l2 != NULL) { sum += l2->val; l2 = l2->next; } carry = sum / 10; newNode = ______________③________________; newNode->val = __________④________; newNode->next = NULL; tail->next = newNode; tail = newNode; } 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 n1, n2; int i; int* arr1; int* arr2; struct ListNode* l1; struct ListNode* l2; struct ListNode* result; printf("请输入第一个链表的节点个数:"); scanf("%d", &n1); arr1 = ____________⑤_____________; printf("请输入第一个链表的 %d 个数字(逆序存储,如 342 输入:2 4 3): ", n1); for (i = 0; i < n1; i++) { scanf("%d", &arr1[i]); } printf(" 请输入第二个链表的节点个数:"); scanf("%d", &n2); arr2 = (int*)malloc(n2 * sizeof(int)); printf("请输入第二个链表的 %d 个数字(逆序存储): ", n2); for (i = 0; i < n2; i++) { scanf("%d", &arr2[i]); } l1 = createList(arr1, n1); l2 = createList(arr2, n2); printf(" 链表 1:"); printList(l1); printf("链表 2:"); printList(l2); result = addTwoNumbers(l1, l2); printf(" 相加结果(逆序):"); printList(result); free(arr1); free(arr2); } 【答案】①l1 != NULL || l2 != NULL || carry != 0 ②sum += l1->val ③(struct ListNode*)malloc(sizeof(struct ListNode)) ④sum % 10 ⑤(int*)malloc(n1 * sizeof(int)) 2.下列程序的功能是:给定一个链表,删除链表的倒数第N个节点,并返回链表的头节点。(每空2分,共10分) 输出结果: 原链表: 1 2 3 4 5 删除倒数第 2 个节点后: 1 2 3 5 #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* removeNthFromEnd(struct ListNode* head, int n) { struct ListNode dummy; struct ListNode* first; struct ListNode* second; struct ListNode* temp; int i; dummy.next = head; first = &dummy; second = &dummy; for (i = 0; i <= n; i++) { first = _____________①____________; } while (first != NULL) { first = first->next; __________②__________; } temp = __________③___________; second->next = temp->next; free(temp); 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 = node; } } return head; } void printList(struct ListNode* head) { struct ListNode* curr; curr = head; while (curr != NULL) { printf("%d ", curr->val); ____________⑤______________; } printf(" "); } main() { int arr[] = {1,2,3,4,5}; int len; int n; struct ListNode* head; struct ListNode* newHead; len = sizeof(arr) / sizeof(arr[0]); head = createList(arr, len); printf("原链表: "); printList(head); n = 2; newHead = removeNthFromEnd(head, n); printf("删除倒数第 %d 个节点后: ", n); printList(newHead); } 【答案】①first->next ②second = second->next ③second->next ④tail->next = node ⑤curr = curr->next 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $

资源预览图

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