c模拟试卷2及答案
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字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [高中教育]电子线路高频非线性部分2.1
- [高中教育]中班美术活动——我的小手
- [高中教育]常用三极管参数大全
- [高中教育]计算机常见故障及解决办法
- [高中教育]风机基础环水平度控制方法探讨
- [高中教育]机械安全工程(专升本)阶段性作业3
- [高中教育]2009年安徽省高考语文考试说明刍议
- [高中教育]unit5 let's eat公开课教案设
- [高中教育]计算机网络原理课后习题答案
- [高中教育]2016-2022年中国新能源市场研究与投资
- [高中教育]2015-2020年中国会议行业市场评估及投
- [高中教育]经销商大会峰会主持人串词开场白
- [高中教育]2014新版北师大数学三年级上册小熊购物
- [高中教育]七年级第一学期体育与健康全套教案
- [高中教育]第三章:国际金融市场
- [高中教育]六年级下册数学单元测试-2.比例 北师大
- [高中教育]2016年上海海事大学法学院624刑法之《
- [高中教育]中国碳化钙产业竞争现状及未来五年投资
- [高中教育]网络时代,我们怎么玩
- [高中教育]圆锥曲线——高中数学基础知识与典型例
- 高集医院世界艾滋病宣传日活动方案
- 苏教版六年级英语上册期末试卷含答案
- 全民枪战生化英雄模式幽灵怎么玩 生化
- 灿烂的宋元文化一导学案
- 第2章货币资金与应收款项
- 北师大版八年级下册数学第三章《分式》
- 浅析高分子材料成型加工技术
- 华南理工大学2013年度共青团先进集体及
- 教师资格科目二小学教案模板(共合集)
- 工程扩建可研报告
- 中华人民共和国海事局2014年度招录公务
- 提高农村小学生作文能力的教学尝试
- 徒手心肺复苏术操作步骤
- 毛概试题库7-15章
- 2014-2015学年度(上)初中班主任工作计
- 企业驾驶员安全生产责任书
- 第07章 不等式测试题-2016年高考文科数
- 医疗器械经营企业工作程序
- 考研英语必背36篇_彩版_精华
- 初中9月13-15假期作业 (1)




