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

2026-03-27
| 2份
| 43页
| 63人阅读
| 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/57044322.html
价格 3.00储值(1储值=1元)
来源 学科网

内容正文:

编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(十)解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.若有定义:int k=9,x=13;,则下列表达式中值不为3的是( ) A.x%=k%=5 B.x%=k-k%5 C.x%=(k-k%5) D.(x%=k)-(k%=4) 【答案】A 【解析】 A:x%=k%=5 → k%=5得k=4,x%=4得x=13%4=1 B:x%=k-k%5 → k%5=4,k-k%5=5,x%=5得x=13%5=3 C:x%=(k-k%5) → 同 B,结果为3 D:(x%=k)-(k%=4) → x%=9得x=13%9=4,k%=4得k=1,4-1=3 2.若有定义,int a=3,*p=&a,**q=&p;,则以下叙述中错误的是( ) A.q是指针变量,*q就是变量a B.p是指针变量,p指向变量a C.q指向变量p,所以*q指向变量a D.*p与**q都代表变量a 【答案】A 【解析】q是指向指针p的指针,*q等价于p,是指针变量,并非变量a;**q才等价于a,故 A 错误。 3.设有字符数组定义:char str[ ]="welcome";,则执行下列语句后的输出结果是( ) printf("%d ",strlen(strcpy(str,"Hello"))); A.7 B.5 C.8 D.9 【答案】B 【解析】strcpy(str,"Hello")将str内容替换为"Hello",strlen("Hello")计算字符串长度为5,故输出5。 4.设有语句:scanf("a=%d,b=%d",&a,&b);为使变量a的值为1,b的值为2,正确的数据输入方式是( ) A.12 B.1,2 C.a=1,b=2 D.a=1 b=2 【答案】C 【解析】scanf格式串"a=%d,b=%d"要求输入必须严格匹配格式,需输入a=1,b=2才能正确赋值。 5.下列选项中,能正确进行字符串操作的语句是( ) A.char a[10]={'A','B','C','D','\0'}; B.char a[10];a="ABCDE"; C.char *p;*p="ABCDE"; D.char *s;scanf("%s",s); 【答案】A 【解析】B项中,字符数组的数组名指向数组的首元素地址,初始化后不可再被更改;CD两项中的字符指针在定义时均没有进行初始化,对其赋值是非法的。 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include <stdio.h> long fun5(int n) { long s; if((n==1)||(n==2)) s=2; else s=n+fun5(n-1); return (s); } main() { long x; x=fun5(4); printf("%ld ",x); } 【答案】9 (2)下列程序的运行结果是_________________。 #include <stdio.h> main() { int a[4][4] = {{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12}, {13, 14, 15, 16} }; int top = 0, bottom = 3, left = 0, right = 3; int sum = 0, cnt = 0; int dir = 0,i; while (top <= bottom && left <= right) { if (dir == 0) { for (i = left; i <= right; i++) { if (a[top][i] % 3 != 0) { sum += a[top][i]; cnt++; } } top++; } else if (dir == 1) { for (i = top; i <= bottom; i++) { if (cnt % 2 == 0) a[i][right] *= 2; sum += a[i][right]; } right--; } else if (dir == 2) { for (i = right; i >= left; i--) { sum += a[bottom][i]; } bottom--; } else { for (i = bottom; i >= top; i--) { if (a[i][left] > 10) sum -= a[i][left]; else sum += a[i][left]; } left++; } dir = (dir + 1) % 4; if (cnt > 5) break; } printf("%d ", sum); } 【答案】138 (3)下列程序的运行结果是_________________。 #include <stdio.h> main() { char s[] = "a*b*c*d*"; char *p = s, *q = s; while (*q) { if (*q != '*') *p++ = *q; q++; } *p = '\0'; printf("%s,%d ", s, p - s); } 【答案】abcd,4 (4)下列程序的运行结果是_________________。 #include <stdio.h> struct Data { int a; int b; }; main() { struct Data d[] = {{1, 2}, {3, 4}}; struct Data *p = d; (p + 1)->a = 10; p->b = (p + 1)->b; printf("%d,%d ", d[0].b, d[1].a); } 【答案】4,10 (5)下列程序的运行结果是_________________。 #include <stdio.h> #include <string.h> int global_counter = 0; int func1(int a, int b) { static int count = 0; count++; global_counter++; return a + b + count;} int func2(int* arr, int n) { int result = 0,i; for (i = 0; i < n; i++) { if (arr[i] % 2 == 0) { result += func1(i, arr[i]); } else { result -= func1(arr[i], i); } } return result;} void swap_values(int* a, int* b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b;} main() { int arr[] = {2, 5, 8, 3, 6}; int n = sizeof(arr) / sizeof(arr[0]); int x = 10, y = 20,i,result1,result2; for (i = 0; i < 3; i++) { swap_values(&x, &y);} result1 = func2(arr, n); result2 = func2(arr, n - 2); printf("x=%d, y=%d ", x, y); printf("result1=%d, result2=%d ", result1, result2); printf("global_counter=%d ", global_counter); } 【答案】 x=20, y=10 result1=13, result2=13 global_counter=8 (6)下列程序的运行结果是_________________。 #include <stdio.h> int main() { int arr[2][3] = {{1,2,3}, {4,5,6}}; int (*p)[3] = arr; int *q = (int*)arr; int result = 0,i,j; for(i = 0; i < 2; i++) { for(j = 0; j < 3; j++) { if((i + j) % 2 == 0) { result += *(*(p + i) + j); } else { result -= q[i * 3 + j]; } } } printf("%d ", result); printf("%d %d ", *(*(p + 1) + 2), *(q + 5)); } 【答案】-3 6 6 (7)下列程序的运行结果是_________________。 #include<stdio.h> main() { char s[100]="Our Class have 50 students!"; int a[3]={0,0,0},i; i=0; while(s[i]!='\0') {if(s[i]>='0'&&s[i]<='9') a[0]++; else if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z') a[1]++; else a[2]++; i++;} for(i=0;i<3;i++) printf("%d ",a[i]);} 【答案】2 20 5 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是将a所指4x3矩阵中第k行的元素与第0行元素交换。 例如,有下列矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 若k为2,程序执行结果为 7 8 9 4 5 6 1 2 3 10 11 12 请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> #define N 3 #define M 4 void fun(int (*a)[N],int k) { int i,temp; for(i =0;_____①____;i++) { temp=a[0][i]; ______②______; a[k][i] =temp; } } main() { int x[M][N]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}},i,j; printf("The array before mov- ing: "); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%3d",x[i][j]); printf(" "); } _______③________; printf("The array after mov- ing: "); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%3d",_______④______); printf(" "); } } 【答案】①i<N ②a[0][i]=a[k][i] ③fun(x,2) ④x[i][j] (2)此程序定义了学生结构体变量,存储了学生的学号,姓名和三门课的成绩。所有学生数据均以二进制方式输出到文件中。函数 fun()的功能是从形参filename所指的文件中读入学生数据,先按照学号从小到大排序后,再用二进制方式把排序后的学生数据输出到flename所指的文件中,覆盖原来的文件内容。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(5空) #include <stdio.h> #define N 5 typedef struct student { long sno; char name[10]; float score[3];}STU; void fun(char *filename) { FILE *fp; int i,j; STU s[N],t; fp = fopen(filename,________①________); fread(__________②____________); fclose(fp); for(i=0;i<N-1;i++) for(j=i+1;j<N;j++) if (_________③__________) {t=s[i];s[i]=s[j]; s[j]=t;} fp = fopen(filename,______④________); fwrite(s, sizeof(STU),N,fp); fclose(fp); } main() {STU t[N]={ {10005,"zhangSan",95,80,88}, {10003,"LiSi",85,70,78}, {10002,"CaoKai",75,60,88}, {10004,"FangFang",90,82,87}, {10001,"MaChao",91,92,77}},ss[N]; int i,j; FILE *fp; fp=fopen("student.dat","wb"); fwrite(t, sizeof(STU),5,fp); fclose(fp); printf(" The original data: "); for (j=0;j<N;j++) {printf(" No:%1d Name:%-8s Scores: ",t[j].sno,t[j].name); for (i=0;i<3;i++) printf("%6.2f",t[j]. score[i]); printf(" "); } fun("student.dat"); printf(" The data after sorting : "); fp = fopen("student.dat","rb"); fread(ss, sizeof(STU), 5, fp); fclose(fp); for (j=0;j<N;j++) {printf(" No:%1d Name:%-8s Scores: ",ss[j].sno, ss[j].name); for(i=0;i<3;i++) printf("%6.2f", ___________⑤________); printf(" "); } } 【答案】①"rb" ②s, sizeof(STU),N, fp ③s[i].sno>s[j].sno ④"wb" ⑤ss[j]. score[i] (3)以下程序的功能是:统计字符串(长度不超过1000个字符)中每个字母的个数(不区分大小写),若字符不是字母,则统一归为其他字符。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include<stdio.h> #include<string.h> _____________①_______________ main() { char s[1000]; int counters[27]= {0},i; printf("Input a string "); gets(s); countstr(s,counters); for(i=0; i<=25;i++) printf("%c : %d ",i+65,counters[i]); printf("others : %d ",counters[i]); } void countstr(char *st,int cutor[]) { int i,j; char t; i=________②_______; for(j=0;j<i;j++) { t=______③______; if(t>='a'&&t<='z') t=t-'a'+'A'; if(t>='A'&&t<='Z') cutor[t-_______④_____ ]++; else cutor[26]++; } } 【答案】①void countstr(char *st,int cutor[]); ②strlen(st) ③st[j] ④ 'A' (4)甲、乙、丙三位鱼夫出海打鱼,他们随船带了21只箩筐。当晚返航时,他们发现有七筐装满了鱼,还有七筐装了半筐鱼,另外七筐则是空的,由于他们没有秤,只好通过目测认为七个满筐鱼的重量是相等的,7个半筐鱼的重量是相等的。下列程序的功能是:在不将鱼倒出来的前提下,将鱼和筐平分为三份。(5空) #include<stdio.h> int a[3][3],count; int main() { int i,j,k,m,n,flag; printf("It exists possible distribtion plans: "); for(i=0;i<=3;i++) { a[0][0]=i; for(j=i;_______①______;j++) { a[1][0]=j; if((a[2][0]=7-j-a[0][0])>3) _______②______; if(a[2][0]<a[1][0]) _______③________; for(k=1;k<=5;k+=2) { a[0][1]=k; for(m=1;m<7-k;m+=2) { a[1][1]=m; a[2][1]=________④_______; for(flag=1,n=0;flag&&n<3;n++) if(a[n][0]+a[n][1]<7&&a[n][0]*2+a[n][1]==7) a[n][2]=_______⑤_________; else flag=0; if(flag) { printf("No.%d Full basket Semi–basket Empty ",++count); for(n=0;n<3;n++) printf(" fisher %c: %d %d %d ",'A'+n,a[n][0],a[n][1],a[n][2]); } } } } } } 【答案】①j<=7-i&&j<=3 ②continue ③break ④7-k-m ⑤7-a[n][0]-a[n][1] 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)下面程序中,函数fun的功能是:将字符串a中的所有字符复制到字符串b中,要求每复制三个字符之后插入一个空格。请改正程序中的错误,使它能得出正确结果。以下程序只允许修改两行。 L1 #include <stdio.h> L2 void fun(char *p, char *b) L3 { int i, k=0; L4 while(*p) L5 { i=1; L6 while( i<=3 || *p ) { L7 b[k]=p; L8 k++; p++; i++; L9 } L10 if(*p) L11 { L12 b[k++]=' '; L13 } L14 } L15 b[k]='\0'; L16 } L17 main() L18 { char a[80],b[80]; L19 printf("Enter a string: "); L20 gets(a); L21 printf("The original string: "); L22 puts(a); L23 fun(a,b); L24 printf(" The string after insert space: "); L25 puts(b); L26 printf(" "); L27 getchar(); L28 } ①___________________________________________________ ②___________________________________________________ 【答案】 ①L6 while( i<=3 && *p ) { ②L7 b[k]=*p; (2)在下列程序中,函数fun的功能是:判定形参a所指的N×N(规定N为奇数)的矩阵是否是"幻方",若是,则函数返回值为1;若不是,则函数返回值为0."幻方"的判定条件是:矩阵每行,每列,主对角线及反对角线上元素之和都相等。 例如,以下3×3的矩阵就是一个"幻方": 4 9 2 3 5 7 8 1 6 请在程序的下划线处填入正确的内容,使程序得出正确的结果。以下程序只允许修改四行。 L1 #include <stdio.h> L2 #define N 3 L3 int fun(int(*a)[N]) L4 { L5 int i,j,m1,m2,row,colum; L6 m1=m2=0; L7 for(i=0;i<N;i++) L8 { L9 j=N-i; L10 m1+=a[i][i]; L11 m2+=a[i][j]; } L12 if(m1==m2) return 0; L13 for(i=0;i<N;i++) L14 { L15 row=colum=0; L16 for(j=0;j<N;j++) L17 { L18 row+=a[i][j]; L19 colum+=a[j][i]; } L20 if((row!=colum)&&(row!=m1)) L21 return 0; } L22 return 0; } L23 main() L24 {int x[N][N],i,j; L25 printf("Enter number for array: "); L26 for(i=0; i<N;i++) L27 for(j=0;j<N;j++) L28 scanf("%d",&x[i][j]); L29 printf("Array: "); L30 for(i=0;i<N;i++) L31 { L32 for(j=0;j<N;j++) L33 printf("%3d",x[i][j]); L34 printf(" "); } L35 if(fun(x)) L36 printf("The Array is a magic square. "); L37 else L38 printf("The Array isn't a magic square. "); } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ ④___________________________________________________ 【答案】①L9 j=N-i-1; ②L12 if(m1!=m2) return 0; ③L20 if((row!=colum)||(row!=m1)) ④L22 return 1; } (3)如果一个数恰好等于它的因子之和,则称该数为“完全数”。下面程序的功能是找出1000以内的完全数。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int a,i,m; L5 printf("There are following perfect numbers smaller than 1000: "); L6 for(a=1;a<1000;a++) L7 { L8 for(m=0,i=1;i<=a/2;i++) L9 if(a%i) L10 m=m+i; L11 if(m!=a) L12 printf("%4d ",a); L13 } L14 printf(" "); L15 } ①___________________________________________________ ②___________________________________________________ 【答案】①L9 if(!(a%i)) ②L11 if(m==a) (4)张三、李四、王五、刘六的年龄成一等差数列,他们四人的年龄相加是26,相乘是880,下列程序的功能是:求以他们的年龄为前4项的等差数列的前20项。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int n,a,i; L5 printf("The series with equal difference are: "); L6 for(n=1;n<=6;n++) L7 for(a=1;a<=4;a++) L8 if(4*n+6*a==26||n*(n+a)*(n+a+a)*(n+a+a+a)==880) L9 for(i=0;i<20;i++) L10 printf("%d ",i*a); L11 } ①___________________________________________________ ②___________________________________________________ 【答案】①L8 if(4*n+6*a==26&&n*(n+a)*(n+a+a)*(n+a+a+a)==880) ②L10 printf("%d ",n+i*a); 三、程序设计题(本大题共2小题,合计20分) 1.下列程序得功能是旋转链表,将链表每个节点向右移动k个位置,其中k是从键盘输入的非负数。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* rotateRight(struct ListNode* head, int k) { struct ListNode* curr; int length; struct ListNode* new_tail; int i; struct ListNode* new_head; if (______________①________________) { return head; } curr = head; length = 1; while (curr->next != NULL) { length++; curr = __________②_________; } k = k % length; if (k == 0) { return head; } new_tail = head; for (i = 0; i < length - k - 1; i++) { new_tail = new_tail->next; } new_head = ___________③___________; new_tail->next = NULL; curr->next = head; return new_head; } 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 = 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; int i; int* arr; int k; 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]); } printf("请输入向右旋转的位数 k:"); scanf("%d", &k); head = createList(arr, len); printf(" 原始链表:"); printList(head); result = rotateRight(head, k); printf("旋转后链表:"); printList(result); free(arr); } 【答案】①head == NULL || head->next == NULL || k == 0 ②curr->next ③new_tail->next ④(struct ListNode*)malloc(sizeof(struct ListNode)) ⑤tail->next = node 2.下列程序的功能是:创建一个链表并输入一个特定值x,对链表进行分隔,使得所有小于x的节点都在大于或等于x的节点之前。保留两个分区中每个节点的原始相对位置。(每空2分,共10分) 原始链表: 1 4 3 2 5 2 以 3 分隔后: 1 2 2 4 3 5 #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* partition(struct ListNode* head, int x) { struct ListNode *before_head, *before_tail; struct ListNode *after_head, *after_tail; struct ListNode *curr; struct ListNode *result; before_head = (struct ListNode*)malloc(sizeof(struct ListNode)); after_head = (struct ListNode*)malloc(sizeof(struct ListNode)); before_head->next = NULL; after_head->next = NULL; before_tail = before_head; after_tail = after_head; curr = head; while (curr != NULL) { if (__________①________) { before_tail->next = curr; before_tail = curr; } else { after_tail->next = curr; after_tail = curr; } curr = curr->next; } after_tail->next = NULL; before_tail->next = __________②__________; result = __________③__________; free(before_head); free(after_head); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode *head, *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 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, x; 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]); } printf("请输入分隔值 x:"); scanf("%d", &x); head = createList(arr, len); printf(" 原始链表:"); printList(head); ____________⑤_____________; printf("分隔后链表(小于%d在前):", x); printList(result); free(arr); } 【答案】①curr->val < x ②after_head->next ③before_head->next ④(struct ListNode*)malloc(sizeof(struct ListNode)) ⑤result = partition(head, x) 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $ 编写说明:本冲刺卷严格依据湖南省计算机应用类高考考纲编写,依托《C语言程序设计》(高等教育出版社第5版),聚焦高三考生冲刺需求,助力高效提分。内容上深度覆盖考纲掌握、理解层级考点,既系统梳理构建知识框架,又强化应用能力训练;同时结合近五年高考真题,精准把握高频考点、命题趋势与题型特点,确保贴合高考方向。 湖南省计算机应用类 《C语言程序设计》 高频考点冲刺卷(十)解析版 时间:60分钟 总分:100分 班级:_________ 姓名:________ 学号:________ 成绩:_________ 一、单选题(在本题的每一小题的备选答案中,只有一个答案是正确的。本大题共5小题,每小题2分,共10分) 1.若有定义:int k=9,x=13;,则下列表达式中值不为3的是( ) A.x%=k%=5 B.x%=k-k%5 C.x%=(k-k%5) D.(x%=k)-(k%=4) 2.若有定义,int a=3,*p=&a,**q=&p;,则以下叙述中错误的是( ) A.q是指针变量,*q就是变量a B.p是指针变量,p指向变量a C.q指向变量p,所以*q指向变量a D.*p与**q都代表变量a 3.设有字符数组定义:char str[ ]="welcome";,则执行下列语句后的输出结果是( ) printf("%d ",strlen(strcpy(str,"Hello"))); A.7 B.5 C.8 D.9 4.设有语句:scanf("a=%d,b=%d",&a,&b);为使变量a的值为1,b的值为2,正确的数据输入方式是( ) A.12 B.1,2 C.a=1,b=2 D.a=1 b=2 5.下列选项中,能正确进行字符串操作的语句是( ) A.char a[10]={'A','B','C','D','\0'}; B.char a[10];a="ABCDE"; C.char *p;*p="ABCDE"; D.char *s;scanf("%s",s); 二、程序分析题(本大题共3小题,共70分) 1.阅读程序,写出运行结果(每空2分,共14分) (1)下列程序的运行结果是_________________。 #include <stdio.h> long fun5(int n) { long s; if((n==1)||(n==2)) s=2; else s=n+fun5(n-1); return (s); } main() { long x; x=fun5(4); printf("%ld ",x); } (2)下列程序的运行结果是_________________。 #include <stdio.h> main() { int a[4][4] = {{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12}, {13, 14, 15, 16} }; int top = 0, bottom = 3, left = 0, right = 3; int sum = 0, cnt = 0; int dir = 0,i; while (top <= bottom && left <= right) { if (dir == 0) { for (i = left; i <= right; i++) { if (a[top][i] % 3 != 0) { sum += a[top][i]; cnt++; } } top++; } else if (dir == 1) { for (i = top; i <= bottom; i++) { if (cnt % 2 == 0) a[i][right] *= 2; sum += a[i][right]; } right--; } else if (dir == 2) { for (i = right; i >= left; i--) { sum += a[bottom][i]; } bottom--; } else { for (i = bottom; i >= top; i--) { if (a[i][left] > 10) sum -= a[i][left]; else sum += a[i][left]; } left++; } dir = (dir + 1) % 4; if (cnt > 5) break; } printf("%d ", sum); } (3)下列程序的运行结果是_________________。 #include <stdio.h> main() { char s[] = "a*b*c*d*"; char *p = s, *q = s; while (*q) { if (*q != '*') *p++ = *q; q++; } *p = '\0'; printf("%s,%d ", s, p - s); } (4)下列程序的运行结果是_________________。 #include <stdio.h> struct Data { int a; int b; }; main() { struct Data d[] = {{1, 2}, {3, 4}}; struct Data *p = d; (p + 1)->a = 10; p->b = (p + 1)->b; printf("%d,%d ", d[0].b, d[1].a); } (5)下列程序的运行结果是_________________。 #include <stdio.h> #include <string.h> int global_counter = 0; int func1(int a, int b) { static int count = 0; count++; global_counter++; return a + b + count;} int func2(int* arr, int n) { int result = 0,i; for (i = 0; i < n; i++) { if (arr[i] % 2 == 0) { result += func1(i, arr[i]); } else { result -= func1(arr[i], i); } } return result;} void swap_values(int* a, int* b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b;} main() { int arr[] = {2, 5, 8, 3, 6}; int n = sizeof(arr) / sizeof(arr[0]); int x = 10, y = 20,i,result1,result2; for (i = 0; i < 3; i++) { swap_values(&x, &y);} result1 = func2(arr, n); result2 = func2(arr, n - 2); printf("x=%d, y=%d ", x, y); printf("result1=%d, result2=%d ", result1, result2); printf("global_counter=%d ", global_counter); } (6)下列程序的运行结果是_________________。 #include <stdio.h> int main() { int arr[2][3] = {{1,2,3}, {4,5,6}}; int (*p)[3] = arr; int *q = (int*)arr; int result = 0,i,j; for(i = 0; i < 2; i++) { for(j = 0; j < 3; j++) { if((i + j) % 2 == 0) { result += *(*(p + i) + j); } else { result -= q[i * 3 + j]; } } } printf("%d ", result); printf("%d %d ", *(*(p + 1) + 2), *(q + 5)); } (7)下列程序的运行结果是_________________。 #include<stdio.h> main() { char s[100]="Our Class have 50 students!"; int a[3]={0,0,0},i; i=0; while(s[i]!='\0') {if(s[i]>='0'&&s[i]<='9') a[0]++; else if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z') a[1]++; else a[2]++; i++;} for(i=0;i<3;i++) printf("%d ",a[i]);} 2.程序填空。按照题目要求,将正确内容填入程序空白处,使程序完整(每空2分,共36分)。 (1)在此程序中,函数fun()的功能是将a所指4x3矩阵中第k行的元素与第0行元素交换。 例如,有下列矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 若k为2,程序执行结果为 7 8 9 4 5 6 1 2 3 10 11 12 请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include <stdio.h> #define N 3 #define M 4 void fun(int (*a)[N],int k) { int i,temp; for(i =0;_____①____;i++) { temp=a[0][i]; ______②______; a[k][i] =temp; } } main() { int x[M][N]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}},i,j; printf("The array before mov- ing: "); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%3d",x[i][j]); printf(" "); } _______③________; printf("The array after mov- ing: "); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%3d",_______④______); printf(" "); } } (2)此程序定义了学生结构体变量,存储了学生的学号,姓名和三门课的成绩。所有学生数据均以二进制方式输出到文件中。函数 fun()的功能是从形参filename所指的文件中读入学生数据,先按照学号从小到大排序后,再用二进制方式把排序后的学生数据输出到flename所指的文件中,覆盖原来的文件内容。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(5空) #include <stdio.h> #define N 5 typedef struct student { long sno; char name[10]; float score[3];}STU; void fun(char *filename) { FILE *fp; int i,j; STU s[N],t; fp = fopen(filename,________①________); fread(__________②____________); fclose(fp); for(i=0;i<N-1;i++) for(j=i+1;j<N;j++) if (_________③__________) {t=s[i];s[i]=s[j]; s[j]=t;} fp = fopen(filename,______④________); fwrite(s, sizeof(STU),N,fp); fclose(fp); } main() {STU t[N]={ {10005,"zhangSan",95,80,88}, {10003,"LiSi",85,70,78}, {10002,"CaoKai",75,60,88}, {10004,"FangFang",90,82,87}, {10001,"MaChao",91,92,77}},ss[N]; int i,j; FILE *fp; fp=fopen("student.dat","wb"); fwrite(t, sizeof(STU),5,fp); fclose(fp); printf(" The original data: "); for (j=0;j<N;j++) {printf(" No:%1d Name:%-8s Scores: ",t[j].sno,t[j].name); for (i=0;i<3;i++) printf("%6.2f",t[j]. score[i]); printf(" "); } fun("student.dat"); printf(" The data after sorting : "); fp = fopen("student.dat","rb"); fread(ss, sizeof(STU), 5, fp); fclose(fp); for (j=0;j<N;j++) {printf(" No:%1d Name:%-8s Scores: ",ss[j].sno, ss[j].name); for(i=0;i<3;i++) printf("%6.2f", ___________⑤________); printf(" "); } } (3)以下程序的功能是:统计字符串(长度不超过1000个字符)中每个字母的个数(不区分大小写),若字符不是字母,则统一归为其他字符。请在程序的下划线处填入正确的内容,使程序得出正确的结果。(4空) #include<stdio.h> #include<string.h> _____________①_______________ main() { char s[1000]; int counters[27]= {0},i; printf("Input a string "); gets(s); countstr(s,counters); for(i=0; i<=25;i++) printf("%c : %d ",i+65,counters[i]); printf("others : %d ",counters[i]); } void countstr(char *st,int cutor[]) { int i,j; char t; i=________②_______; for(j=0;j<i;j++) { t=______③______; if(t>='a'&&t<='z') t=t-'a'+'A'; if(t>='A'&&t<='Z') cutor[t-_______④_____ ]++; else cutor[26]++; } } (4)甲、乙、丙三位鱼夫出海打鱼,他们随船带了21只箩筐。当晚返航时,他们发现有七筐装满了鱼,还有七筐装了半筐鱼,另外七筐则是空的,由于他们没有秤,只好通过目测认为七个满筐鱼的重量是相等的,7个半筐鱼的重量是相等的。下列程序的功能是:在不将鱼倒出来的前提下,将鱼和筐平分为三份。(5空) #include<stdio.h> int a[3][3],count; int main() { int i,j,k,m,n,flag; printf("It exists possible distribtion plans: "); for(i=0;i<=3;i++) { a[0][0]=i; for(j=i;_______①______;j++) { a[1][0]=j; if((a[2][0]=7-j-a[0][0])>3) _______②______; if(a[2][0]<a[1][0]) _______③________; for(k=1;k<=5;k+=2) { a[0][1]=k; for(m=1;m<7-k;m+=2) { a[1][1]=m; a[2][1]=________④_______; for(flag=1,n=0;flag&&n<3;n++) if(a[n][0]+a[n][1]<7&&a[n][0]*2+a[n][1]==7) a[n][2]=_______⑤_________; else flag=0; if(flag) { printf("No.%d Full basket Semi–basket Empty ",++count); for(n=0;n<3;n++) printf(" fisher %c: %d %d %d ",'A'+n,a[n][0],a[n][1],a[n][2]); } } } } } } 3.阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构,请在作答处指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共20分)。 (1)下面程序中,函数fun的功能是:将字符串a中的所有字符复制到字符串b中,要求每复制三个字符之后插入一个空格。请改正程序中的错误,使它能得出正确结果。以下程序只允许修改两行。 L1 #include <stdio.h> L2 void fun(char *p, char *b) L3 { int i, k=0; L4 while(*p) L5 { i=1; L6 while( i<=3 || *p ) { L7 b[k]=p; L8 k++; p++; i++; L9 } L10 if(*p) L11 { L12 b[k++]=' '; L13 } L14 } L15 b[k]='\0'; L16 } L17 main() L18 { char a[80],b[80]; L19 printf("Enter a string: "); L20 gets(a); L21 printf("The original string: "); L22 puts(a); L23 fun(a,b); L24 printf(" The string after insert space: "); L25 puts(b); L26 printf(" "); L27 getchar(); L28 } ①___________________________________________________ ②___________________________________________________ (2)在下列程序中,函数fun的功能是:判定形参a所指的N×N(规定N为奇数)的矩阵是否是"幻方",若是,则函数返回值为1;若不是,则函数返回值为0."幻方"的判定条件是:矩阵每行,每列,主对角线及反对角线上元素之和都相等。 例如,以下3×3的矩阵就是一个"幻方": 4 9 2 3 5 7 8 1 6 请在程序的下划线处填入正确的内容,使程序得出正确的结果。以下程序只允许修改四行。 L1 #include <stdio.h> L2 #define N 3 L3 int fun(int(*a)[N]) L4 { L5 int i,j,m1,m2,row,colum; L6 m1=m2=0; L7 for(i=0;i<N;i++) L8 { L9 j=N-i; L10 m1+=a[i][i]; L11 m2+=a[i][j]; } L12 if(m1==m2) return 0; L13 for(i=0;i<N;i++) L14 { L15 row=colum=0; L16 for(j=0;j<N;j++) L17 { L18 row+=a[i][j]; L19 colum+=a[j][i]; } L20 if((row!=colum)&&(row!=m1)) L21 return 0; } L22 return 0; } L23 main() L24 {int x[N][N],i,j; L25 printf("Enter number for array: "); L26 for(i=0; i<N;i++) L27 for(j=0;j<N;j++) L28 scanf("%d",&x[i][j]); L29 printf("Array: "); L30 for(i=0;i<N;i++) L31 { L32 for(j=0;j<N;j++) L33 printf("%3d",x[i][j]); L34 printf(" "); } L35 if(fun(x)) L36 printf("The Array is a magic square. "); L37 else L38 printf("The Array isn't a magic square. "); } ①___________________________________________________ ②___________________________________________________ ③___________________________________________________ ④___________________________________________________ (3)如果一个数恰好等于它的因子之和,则称该数为“完全数”。下面程序的功能是找出1000以内的完全数。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int a,i,m; L5 printf("There are following perfect numbers smaller than 1000: "); L6 for(a=1;a<1000;a++) L7 { L8 for(m=0,i=1;i<=a/2;i++) L9 if(a%i) L10 m=m+i; L11 if(m!=a) L12 printf("%4d ",a); L13 } L14 printf(" "); L15 } ①___________________________________________________ ②___________________________________________________ (4)张三、李四、王五、刘六的年龄成一等差数列,他们四人的年龄相加是26,相乘是880,下列程序的功能是:求以他们的年龄为前4项的等差数列的前20项。以下程序只允许修改两行。 L1 #include<stdio.h> L2 int main() L3 { L4 int n,a,i; L5 printf("The series with equal difference are: "); L6 for(n=1;n<=6;n++) L7 for(a=1;a<=4;a++) L8 if(4*n+6*a==26||n*(n+a)*(n+a+a)*(n+a+a+a)==880) L9 for(i=0;i<20;i++) L10 printf("%d ",i*a); L11 } ①___________________________________________________ ②___________________________________________________ 三、程序设计题(本大题共2小题,合计20分) 1.下列程序得功能是旋转链表,将链表每个节点向右移动k个位置,其中k是从键盘输入的非负数。(每空2分,共10分) #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* rotateRight(struct ListNode* head, int k) { struct ListNode* curr; int length; struct ListNode* new_tail; int i; struct ListNode* new_head; if (______________①________________) { return head; } curr = head; length = 1; while (curr->next != NULL) { length++; curr = __________②_________; } k = k % length; if (k == 0) { return head; } new_tail = head; for (i = 0; i < length - k - 1; i++) { new_tail = new_tail->next; } new_head = ___________③___________; new_tail->next = NULL; curr->next = head; return new_head; } 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 = 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; int i; int* arr; int k; 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]); } printf("请输入向右旋转的位数 k:"); scanf("%d", &k); head = createList(arr, len); printf(" 原始链表:"); printList(head); result = rotateRight(head, k); printf("旋转后链表:"); printList(result); free(arr); } 2.下列程序的功能是:创建一个链表并输入一个特定值x,对链表进行分隔,使得所有小于x的节点都在大于或等于x的节点之前。保留两个分区中每个节点的原始相对位置。(每空2分,共10分) 原始链表: 1 4 3 2 5 2 以 3 分隔后: 1 2 2 4 3 5 #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode* next; }; struct ListNode* partition(struct ListNode* head, int x) { struct ListNode *before_head, *before_tail; struct ListNode *after_head, *after_tail; struct ListNode *curr; struct ListNode *result; before_head = (struct ListNode*)malloc(sizeof(struct ListNode)); after_head = (struct ListNode*)malloc(sizeof(struct ListNode)); before_head->next = NULL; after_head->next = NULL; before_tail = before_head; after_tail = after_head; curr = head; while (curr != NULL) { if (__________①________) { before_tail->next = curr; before_tail = curr; } else { after_tail->next = curr; after_tail = curr; } curr = curr->next; } after_tail->next = NULL; before_tail->next = __________②__________; result = __________③__________; free(before_head); free(after_head); return result; } struct ListNode* createList(int arr[], int n) { struct ListNode *head, *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 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, x; 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]); } printf("请输入分隔值 x:"); scanf("%d", &x); head = createList(arr, len); printf(" 原始链表:"); printList(head); ____________⑤_____________; printf("分隔后链表(小于%d在前):", x); printList(result); free(arr); } 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $

资源预览图

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