教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 高中教育 >

c模拟试卷2及答案

来源:网络收集 时间:2026-10-05
导读: C语言模拟试卷2 一、选择题 二、改错题 1、下列程序的功能是:统计输入字符串中小写英文字母的个数。 例如,输入:abcdEFGHIJK123 输出:4 #include stdio.h #include string.h main() { char str1[128]; /**/ int i;len, sum=0; /**/ 改为:/**/ int i, len

C语言模拟试卷2

一、选择题 二、改错题

1、下列程序的功能是:统计输入字符串中小写英文字母的个数。 例如,输入:abcdEFGHIJK123 输出:4 #include <stdio.h> #include <string.h> main()

{ char str1[128];

/**/ int i;len, sum=0; /**/ 改为:/**/ int i, len, sum=0; /**/ gets(str1);

len = strlen(str1); for(i=0; i<len; i++)

{ /**/ if( str1[i] >= 'a' || str1[i] <= 'z') /**/ 改为:/**/ if( str1[i] >= 'a' &&str1[i] <= 'z') /**/ sum++; }

printf("%d\n",sum); getch(); }

2、下列程序的功能是:将从键盘中输入的M个数逆序输出。 例如:输入:23 45 4 688 376 89 3 5 12

输出:12 5 3 89 376 688 4 45 23

#define M 9 main()

{ int a[M],i;

printf("Please input 8 numbers:\n"); for(i=0; i<M; i++)

scanf("%d", /**/ a[i] /**/); 改为:/**/& a[i] /**/ printf("Inverse order is: \n");

/**/ for(i=M-1; i<=0; i--) /**/ 改为:/**/ for(i=M-1; i>=0; i--) /**/ printf("%d ", a[i]); printf("\n" ); getch(); }

3、1、下列程序的功能是:统计输入字符串中大写英文字母的个数。 例如,输入:abcdEFGHIJK123 输出:7 #include <stdio.h> #include <string.h> main()

{ /**/ char str1 /**/; 改为:/**/ char str1[20] /**/ int i,len, sum=0;

printf("Please input a string:\n"); scanf("%s", str1); len = strlen(str1); for(i=0; i<len; i++)

{ if( str1[i] >= 'A' && str1[i] <= 'Z')

/**/ sum--; /**/ 改为:/**/ sum++; /**/ }

printf("%d\n",sum); getch(); }

4、下列程序的功能是:从键盘中依次输入M个数,输出其中所有的偶数。 例如:输入:23 45 4 688 376 89 3 5 12

输出:4 688 376 12

/**/ #include M 5 /**/ 改为:/**/ #define M 5 /**/ main()

{ int a[M],i;

printf("Please input 5 numbers:\n"); for(i=0; i<M; i++) scanf("%d", &a[i]); printf("Even numbers:\n" ); for(i=0; i<M; i++)

/**/ if( a[i]/2 ==0) /**/ 改为:/**/ if( a[i]%2 ==0) /**/ printf("%d ", a[i]); printf("\n" ); getch(); }

5、下列程序的功能是:将输入字符串中’0’~’8’的数字字符变为比它大1的数字字符,将’9’变为’0’。如输入:ab12cd56EF89GH4 输出:ab23cd67EF90GH5 #include <stdio.h> #include <string.h> main()

{ char str1[128], str2[128]; int i,len; gets(str1);

len = strlen(str1);

/**/ for(i=0; i>len; i++) /**/ 改为:/**/ for(i=0; i<len; i++) /**/ { if( str1[i] >= '0' && str1[i] <= '8') str2[i] = str1[i] + 1; else if(str1[i] == '9') str2[i] = '0'; else

str2[i] = str1[i]; }

/**/ str2[i] = '\n'; /**/ 改为:/**/ str2[i] = ' \0 '; /**/ puts(str2); getch();

}

6、下列程序的功能是:将程序中的两个字符串”ABC”和”xyz”连接在一起,并输出”ABCxyz”。

#include <stdio.h> #include <string.h> void main()

{ char s1[12]="ABC", s2[]="xyz"; char * ps1=s1,*ps2;

/**/ ps2 = NULL; /**/ 改为:/**/ ps2 = s2; /**/

/**/ while(*ps1 == NULL) /**/ 改为:/**/ while(*ps1!= NULL) /**/ ps1++;

while(*ps2) *(ps1++) = *(ps2++); printf("%s\n",s1); getch(); }

三、填空题 注意:(1)编写程序,补充在每对“/**/”之间的空白处,以完成题目的要求;

(2)不得删改程序中所有的“/**/”注释和其它代码;

1、补充下列程序,使其实现输入一个同学的名字(如“Jack”),输出问候该同学的信息(“Hello, Jack !”)。

/**/ /**/ <stdio.h> 填:#include main()

{ /**/ /**/ str[11]; 填:char printf("Please input a name:\n"); scanf("%s",str);

printf("Hello,%s!\n", str); getch(); }

2、补充下列程序,使程序中的sort( )函数用冒泡法对a中的m个数进行从大到小排序。

#include <stdio.h> #include <math.h> void sort(int a[], int m) { int i, j, t,swap;

for( i=0; i< /**/ /**/ ; i++ ) 填:m { swap = 0;

for( j=0; j < m-i-1; j++)

{ if /**/ /**/ 填:a[j]<a[j+1] { swap = 1; t = a[j];

a[j] = /**/ /**/; 填:a[j+1] a[j+1] = t;

}

if(!swap) break; } }

void main() {

int a[] = {23,55,8,32,18,2,9}; int i,k = sizeof(a)/sizeof(int); sort(a,k);

for(i=0;i<k;i++)

printf("%d ",a[i]); printf("\n"); getch(); }

3、补充下列程序,使程序中的fun( )函数能根据勾股定理判断一个三角形是否为直角三角形,即从键盘上输入一个三角形的三条边a,b,c,若能构成直角三角形就返回1,不能则返回0。

#include <stdio.h> #include <math.h>

int fun(/**/ /**/) 填:float a,float b,float c { float temp; int bTrue = 0; if(a<b)

{ temp = a; a = b; b = temp; } if(a<c)

{ temp = a; a = c; c = temp; }

if( fabs(/**/ /**/ - (b*b + c*c)) < 1.0e-15) 填: a*a bTrue = 1; return bTrue; }

main()

{ float a,b,c;

printf("Please input three numbers:\n"); scanf("%f%f%f",&a,&b,&c);

if( fun(a,b,c) == 1) printf("Yes\n"); else printf("No\n");

}

4、补充下列程序,使其实现从键盘输入一个整数,输出该数的平方。 #include <stdio.h> main() { int x;

printf("Please input a number:\n"); scanf("%d",/**/ /**/); 填:&x

printf("%d*%d=%d\n", x,x,/**/ /**/); 填: x*x getch(); } 5、补充下列程序,使程序中的sort( )函数用选择法对a中的m个数进行从小到大排序。 #include <stdio.h> #include <math.h> void sort(int a[], int m) { int i, j, k, t;

for( i = 0; i < m …… 此处隐藏:6474字,全部文档内容请下载后查看。喜欢就下载吧 ……

c模拟试卷2及答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1728510.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150份
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150份
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)