您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页c语言 资料汇总2009版本_修正版删除链表

c语言 资料汇总2009版本_修正版删除链表

来源:好走旅游网
第一部分:选择题(40分,20小题/套)

概述

1、下面关于C语言的叙述中,正确的是()

A. 每行只能写一条语句 B. 程序中必须包含有输入语句 C. main函数必须位于文件的开头 D. 每条语句最后必须有一个分号 2、下面关于C语言的叙述中,错误的是() A. 若一条语句较长,也可分写在下一行上 B. 构成C语言源程序的基本单位是表达式 C. C语言源程序中大、小写字母是有区别的 D. 一个C语言源程序可由一个或多个函数组成 3、关于C语言数据类型的叙述,正确的是()

A. 枚举类型不是基本类型 B. 数组不是构造类型 C. 变量必须先定义后使用 D. 不允许使用空类型 4、C程序中main函数的位置()

A. 必须在最开始 B. 必须在系统库函数后面 C. 可以在自定义函数后面 D. 必须在最后 5、C语言的函数体由()括起来 A. ( ) B. { } C. [ ] D. /* */

6、关于C语言的叙述中,不正确的是()

A. C程序可由一个或多个函数组成 B. C程序必须包含一个main()函数 C. C程序的基本组成单位是函数 D. 注释说明只能位于一条语句的后面 7、一个程序的执行是从()

A. 本程序的第一个函数开始,到最后一个函数结束 B. 本程序的main函数开始,到main函数结束 C. 本程序的main函数开始,到最后一个函数结束 D. 本程序的第一个函数开始,到main函数结束 8、结构化程序设计的三种基本结构是()

A. 函数结构、分支结构、判断结构 B. 函数结构、嵌套结构、平行结构 C. 顺序结构、分支结构、循环结构 D. 分支结构、循环结构、嵌套结构 9、调试程序是指对程序进行()

A. 编辑 B. 编译 C. 查错和排错 D. 连接

10、C语言中,复合语句的构成是将一系列语句置于() A. begin与end之间 B. 一对圆括号“( )”之间 C. 一对花括号“{ }”之间 D. 一对方括号“[ ]”之间 11、构成C语言源程序的基本单位是()

A. 语句 B. 过程 C. 表达式 D. 函数

语法基础

12、在C语言中,正确的用户标识符是() A. 3f B. _for C. struct D. _f.5

1

13、C语言的基本数据类型包括()

A. 整型、实型、字符型 B. 整型、实型、字符型、逻辑型 C. 整型、字符型、逻辑型 D. 整型、实型、逻辑型 14、以下()是正确的常量

A. E-5 B. 1E5.1 C. „a12‟ D. 32766L 15、以下()是正确的变量名

A. a.bee B. –p11 C. int D. p_11 16、以下()是正确的字符常量

A. “c” B. „//” C. „W‟ D. “\\32a” 17、以下()是不正确的字符串常量

A. „abc‟ B. “12‟12” C. “0” D. “ “ 18、C语言的整型数据在内存中的存储形式是()

A. 原码 B. 反码 C. 补码 D. ASCII码 19、以下()是正确的浮点数

A. e3 B. .62 C. 2e4.5 D. 123 20、下列不属于C语言关键字的是()

A. continue B. integer C. static D. signed 21、C语言的字符型数据在内存中的存储形式是() A. 原码 B. 补码 C. 反码 D. ASCII 22、在C语言中,变量所分配的内存空间大小是() A. 由变量的类型决定 B. 由用户自己决定 C. 任意的 D. 均为两个字节

23、若有定义:int a=2;则正确的赋值表达式是()

A. a-=(a*3) B. double(-1) C. a*3 D. a*4=3 24、语句x=(a=3,b=++a);运行后,x、a、b的值依次为() A. 3,3,4 B. 4,4,3 C. 4,4,4 D. 3,4,3 25、语句a=(3/4)+3%2;运行后,a的值为() A. 0 B. 1 C. 2 D. 3

26、以下四项中,符合C语言语法的语句是()

A. int a+b=c; B. int a=12:b=12:c=12; C. int a=12,b=12,c=12; D. int a,b=12,float c=21

27、若有定义:int x,a;则语句x=(a=3,a+1);运行后,x、a的值依次为() A. 3,3 B. 4,4 C. 4,3 D. 3,4

28、若变量已正确定义并赋值,符合C语言语法的表达式是()

A. a=8+b+c,a++ B. a=3a C. int(12.3%4) D. a=a+1=c+b 29、若有定义:int a,b;double x;则以下不符合C语言语法的表达式是() A. x%(-3) B. a+=-1 C. a=b=2 D. x=a+b

30、若有定义:int x=2,y=3;float i;则以下符合C语言语法的表达式是() A. x=x*3=2 B. x=(y==1) C. i=float(x) D. i%(-3) 31、若有定义:int x;则语句x=(2*3)+6%5;运行后,x的值是() A. 8 B. 7 C. 6 D. 5

32、下面关于C语言变量的叙述中,错误的是()

A. 可以用const关键字定义变量 B. 在C程序中,SUM和sum是不同的变量C. 变量名必须由字母或下划线组成 D. 变量的类型确定了变量的取值范围

2

33、若有定义:int x=5,y=6;则表达式x=(y==6)的值为() A. 5 B. 1 C. 6 D. 0 34、下面叙述正确的是()

A. 2/3与2.0/3.0等价 B. (int)2.0/3与2/3等价 C. ++5与6等价 D. „A‟与”A”等价 35、下面叙述中,错误的是()

A. C语言基本的算术运算符不包含模运算符”%” B. 算术运算符的优先级高于关系运算符

C. 自加和自减运算符的结合方向是”自右向左”

D. C语言规定在表达式求值时,按其中运算符的优先级先高后低的次序进行 36、下面叙述正确的是()

A. 强制类型转换运算的优先级高于算术运算 B. 若a和b是整型变量,(a+b)++是合法的 C. „A‟*‟B‟是不合法的 D. “A”+”B”是合法的 37、若有定义:int i=1,j=5;则表达式(++j)*(i--)的值为() A. 1 B. 0 C. 6 D. 7

38、设整型变量a为5,使b不为2的表达式是()

A. b=(++a)/3 B. b=6-(--a) C. b=a%2 D. b=a/2

39、若有定义:int a=1,b=2,c=3;则语句++a||++b&&++c;运行后b的值为() A. 1 B. 0 C. 2 D. 3

40、若有定义:int i,j;则表达式(i=2,j=5,i++,i+j++)的值是() A. 7 B. 8 C. 9 D. 10

41、若有定义:int a,b;则表达式(a=2,b=5,a*2,b++,a+b)的值是() A. 7 B. 8 C. 9 D. 10

42、若有定义:int i=2,j=5;则表达式(i+1,j+1,(++i+(j--))的值为() A. 8 B. 6 C. 7 D. 5

43、若已定义:int i=3,k;则语句k=(i--)+(i--);运行后k的值为() A. 4 B. 5 C. 6 D. 7

44、C语言的运算符按运算对象的个数可以分为() A. 单目运算符一种 B. 单目和双目运算符

C. 单目、双目和三目运算符 D. 单目、双目、三目和四目运算符

45、若已定义:float m;拟从键盘输入135.78这一数据给变量m,则应选用的语句是() A. scanf(“%5.2f”,&m); B. scanf(“%3.2f”,&m); C. scanf(“6.2f”,&m); D. scanf(“%6f”,&m);

46、已知double a;使用scanf()函数输入一个数值给变量a,正确的函数调用是() A. scanf(“%ld”,&a); B. scanf(“%lf”,&a); C. scanf(“%c”,&a); D. scanf(“%u”,&a);

47、已知char a;使用scanf()函数输入一个字符给变量a,不正确的函数调用是()

A. scanf(“%d”,&a); B. scanf(“%lf”,&a); C. scanf(“%c”,&a); D. scanf(“%u”,&a); 48、putchar()函数的功能是向终端输出()

A. 多个字符 B. 一个字符 C. 一个实型变量值 D. 一个整型变量表达式 49、以下程序段运行后的输出结果是() int k=11;

printf(“k=%d,k=%o,k=%x\\n”,k,k,k);

A. k=11,k=13,k=c B. k=11,k=12,k=13

3

C. k=11,k=13,k=b D. k=11,k=13,k=a

50、若有定义:int x=1234,y=123,z=12;则语句printf(“%4d+%3d+%2d”,x,y,z);运行后的输出结果为()

A. 123412312 B. 12341234123412341231231231212 C. 1234+1234+1234 D. 1234+123+12 51、已有如下定义和输入语句,

int a;char c1,c2;

scanf(“%d%c%c”,&a,&c1,&c2);

若要求a、c1、c2的值分别为10、A和B,正确的数据输入是() A. 10AB B. 10 A B C. 10A B D. 10 AB 52、以下程序段的运行结果是()

int a=0,b=0,c=0; if(a&&++b) c++;

printf(“%d,%d\\n”,b,c);

A. 0,0 B. 1,2 C. 2,2 D. 1,0 53、以下程序的运行结果是()

void main() {

int a=65; char c=‟A‟;

printf(“%x,%d”,b,c); }

A. 65,a B. 41,a C. 65,65 D. 41,65

、若已定义:int a=5;float b=63.72;以下语句中能输出正确值的是() A. printf(“%d%d”,a,b); B. printf(“%d%2f”,a,b); C. printf(“%2f%2f”,a,b); D. printf(“%2f%d”,a,b); 55、运行以下程序段时编译出错,其原因是()

char c1='8',c2='2008'; printf(\"%c,%d\\n\

A. c2是字符变量,只能赋以字符常量,不能赋以字符串常量 B. 字符串要用“2008“表示,而‘2008’不是字符串表示 C. ‘2008’只能赋值给字符数组 D. 字符变量不能用%d格式输出

56、若已定义:int a=3,b=15,c;则语句c=a>b;运行后c的值为() A. 1 B. 0 C. t D. f

57、在C语言中,判定逻辑值为“真“的最正确的叙述是()

A. 1 B. 非0的数 C. 大于0的数 D. 非0的整数 58、若已定义:int a=-36,b=-30,c;则语句c=a59、能正确表示数学关系式800>=y>=500的C语言表达式为() A. (y<=800)&&(y>=500) B. (y<=800)AND(y>=500) C. 800>=y>=500 D. (y<=800)&(y>=500) 60、若有定义:int x=3,y=4;则表达式!x||y的值为()

4

A. 1 B. 0 C. 3 D. 4

61、若有定义:int i=7,j=8;则表达式i>=j||iA. 1 B. 变量i的值 C. 0 D. 变量j的值 62、若希望当a的值为奇数时,表达式的值为“真”,a的值为偶数时,表达式的值为”假”。则不能满足要求的表达式是()

A. a%2==1 B. !(a%2==0) C. !(a%2) D. a%2 63、若有定义:int x=3,y=4,z=5;则值为0 的表达式是() A. ‘x’&&y B. x<=y

C. x||y+z&&y-z D. !((x、若有定义:int a=5,b=2,c=1;则表达式a-b65、C语言中,能正确表示条件10A. 1010||x<20 C. x>10&&<20 D. (x>10)&&(x<20) 66、以下运算符中优先级最低的是() A. << B. & C. >> D. |

67、已知double a=5.2;则正确的赋值表达式是() A. a+=a-=(a=4)*(a=3) B. a=a*3=2 C. a%3 D. a=double(-2) 68、已知char a='R';则正确的赋值表达式是()

A. a=(a++)%4 B. a+2=3 C. a+=256-- D. a=‟\\078‟ 69、已知int a=‟R‟;则正确的表达式是()

A. a%10 B. a=int(3e2) C. 2*a=a++ D. a=a+a=a+3 70、设有语句float x=3.0,y=3.0;使x值为6.0的表达式是() A. x*=y-4 B. x*=y C. x=y+4 D. x+=y

71、若有定义:float x=3.5,int z=8;则表达式x+z%3/4的值为() A. 3。75 B. 3.5 C. 3 D. 4

72、设有语句int x=3,y=3,a=1,b=2;表达式(x=a>b)&&(y=b>a)的值是() A. 8 B. 1 C. 5 D. 0 73、若有定义:int a=2,b=3;float x=3.5,y=2.5;

则表达式(float)(a+b)/2+(int)x%(int)y的值是() A. 3.5 B. 3.0 C. 2.5 D. 2.0

74、若有定义:int b=7;float a=2.5,c=4.7;则表达式a+(b/2*(int)(a+c)/2)%4的值是() A. 2.5 B. 3.5 C. 4.5 D. 5.5

75、若有定义:int a=6,b=2;char c1=‟a‟,c2=‟b‟;则表达式a+b%5+c2-c1的值是() A. 7 B. 8 C. 9 D. 表达式错误 76、在下列运算符中,优先级最高的运算符是() A. <= B. != C. ! D. ||

77、设有定义:char c;float f;int i;unsigned u;double d;下列各表达式的类型分别是()

1. u+9 2. d!=f&&(i+2) 3. 8.2*i+c

A. 1. unsigned,2.int,3.double B. 1.double,2.double,3.double C. 1.int,2.double,3.char D. 1.unsigned,2.double,3.int

5

控制结构

78、以下程序段运行时,若从键盘输入10,则输出结果是()

int a;

scanf(“%d”,&a); if(a++>10)

printf(“%d\\n”,a); else

printf(“%d\\n”,++a);

A. 2 B. 11 C. 3 D. 12 79、以下程序的运行结果是()

void main() {

int x,y=1,z; z=-1; if(z==0) z=-z; else

x=y>0?3:5;

printf(“%d\\n”,x); }

A. -1 B. 3 C. 1 D. 5

80、对于整型变量x,下属if语句()与赋值语句:x=x%2==0?1:0;不等价。 A. if(x%2!=0) x=0;else x=1; B. if(x%2) x=1;else x=0; C. if(x%2==0) x=1;else x=0; D. if(x%2==1) x=0;else x=1; 81、以下程序段运行的结果是() int a,b,c,x; a=b=c=0;x=15; if(!a) x--; else if(b); if(c) x=3; else x+=4;

printf(\"%d\\n\

A. 15 B. 17 C. 18 D. 19

82、若有定义:int a=1,b=2,c=3;则执行以下程序段后a,b,c的值分别为()

if(a{c=a;a=b;b=c;}

A. a=1,b=2,c=3 B. a=2,b=3,c=1 C. a=2,b=3,c=3 D. a=2,b=1,c=1 83、以下程序段运行后变量a的值为()

int x=6,y=5; int a;

a=(--x==y++)?x:y+1

A. 0 B. 1 C. 6 D. 5

6

84、以下程序的运行结果是()

void main() {

int n=‟e‟; switch(n--) {

defalut:printf(“error ”); case „a‟:

case „b‟:printf(“good”);break; case „c‟:printf(“pass”); case „d‟:printf(“warn”); } }

A. error B. good C. error good D. warn 85、以下程序的运行结果是()

void main() {

int n=‟c‟; switch(n++) {

defalut:printf(“error”); case „a‟:

case „b‟:printf(“good”);break; case „c‟:printf(“pass ”); case „d‟:printf(“warn”); } }

A. pass B. warn C. pass warn D. error 86、以下程序的运行结果是()

void main() {

int n=5; if(n++>6)

printf(“%d\\n”,n); else

printf(“%d\\n”,++n); }

A. 4 B. 5 C. 6 D. 7

87、下面关于switch语句的叙述中,错误的是() A. case后面的表达式可以是关系表达式 B. switch语句是多分支选择语句

C. 每一个case后面的值必须互不相同,否则会出现矛盾的现象

D. 在执行一个case分支后,可用一个break语句使流程跳出switch语句88、若有定义:int a=1,b=2,c=3;则以下程序段运行后c的值为()

7

if(a>b) c=a*b; else c=a-b;

A. 2 B. 0 C. 1 D. -1

、若有定义:int x;以下不会产生死循环的是() A. for(;(x=getchar())!=‟\\n‟;); B. while(1){x++;} C. for(i=10;;i++); D. for(;;x+=1);

90、在循环语句的循环体中,break语句的作用是() A. 暂停程序的运行 B. 结束本次循环

C. 继续执行break语句之后的循环体各语句 D. 提前结束循环,接着执行该循环后续的语句

91、以下程序段运行后,循环体中的“count+=2;”语句运行的次数为()

int i,j,count=0; for(i=1;i<=4;i++) {

count+=2;

printf(“%d”,count); }

A. 4次 B. 10次 C. 16次 D. 20次

92、在c语言中while循环和do-while循环的主要区别是()

A. do-while循环体内可以使用break语句,while循环体内不能使用break语句 B. do-while的循环体至少无条件执行一次,while的循环体不是

C. do-while循环体可以使用continue语句,while循环体内不能使用continue语句D. while的循环体至少无条件执行一次,do-while的循环体不是 93、以下程序段运行后,循环体运行的次数为()

int i=0,x;

for(;i<10;i++) x=x+i;

A. 10 B. 0 C. 1 D. 无限 94、以下程序段运行后变量n的值为()

int i=1,n=1; for(;i<3;i++)

{continue;n=n+i;}

A. 4 B. 3 C. 2 D. 1 95、有以下程序:

void main() {

int i;

for(i=0;i<3;i++) switch(i) {

case 1:printf(“%d”,i); case 2:printf(“%d”,i); case 3:printf(“%d”,i);

8

}

}

执行后输出的结果是()

A. 11122 B. 01222 C. 013020 D. 120 96、以下程序的运行结果是()

void main() {

int sum=0,item=0; while(item<5) {

item++; sum+=item; if(sum>=6) break; }

printf(“%d\\n”,sum); }

A. 10 B. 15 C. 6 D. 7 97、以下程序的运行结果是()

voin main() {

int sum=0,item=0; while(item<5) {

item++;

if(item==2) continue; sum+=item; }

printf(“%d\\n”,sum); }

A. 10 B. 13 C. 15 D. 1 98、以下程序段执行后变量sum的值为()

int i,j=1,sum=0; for(i=1,i<=3,i++) {

sum+=j; j++; }

A. 5 B. 3 C. 6 D. 4 99、以下程序的运行结果是()

#include main() {

9

int y=10; do

{y--;} while(--y);

printf(\"%d\\n\}

A. 1 B. 2 C. -1 D. 0

数组

100、C语言中数组元素下标的数据类型是() A. 实型常量 B. 整型常量或整型表达式 C. 任何类型的表达式 D. 字符型常量 101、下列数组定义中,正确的是()

A. int a[10]; B. int n=10,a[n];

C. int N=10;int a[N]; D. int n;scanf(“%d”,&n);int a[n]; 102、若已定义:int a[13];则不能正确引用a数组的元素的是() A. a[0] B. a[10] C. a[10+3] D. a[13-5] 103、若有定义:int a[3]={0,1,2};则a[1]的值为() A. 0 B. 1 C. 2 D. 3 104、若有定义:int a[5]={1,2,3,4,5};

则语句a[1]=a[2]+a[2+2]-a[3-1];运行后a[1]的值为() A. 6 B. 5 C. 1 D. 2 105、以下合法的数组定义是()

A. int a[]=“string”; B. int a[5]={0,1,2,3,4,5}; C. char a[]={0,1,2,3,4,5}; D. char s={“string”}; 106、若有如下程序段:

char s[10]; s=“abcd”;

printf(“%s\\n”,s); 则()。

A. 执行时输出:abcd B. 执行时输出:a C. 执行时输出:ab D. 编译不通过 107、下面程序段的运行结果是()

int i=0,a[]={7,5,7,3,8,3}; do{

a[i]+=2;

}while(a[++i]>5); for(i=0;i<6;i++) printf(\"%d\

A. 9 7 9 5 10 5 B. 9 5 9 3 10 3 C. 9 5 7 3 8 3 D. 7 5 7 3 8 3 108、下面程序段的运行结果是()

int i=0,a[]={1,2,3,4,5}; do{

10

a[i]+=10;

}while(a[++i]>2); for(i=0;i<5;i++) printf(\"%d\

A. 11 2 3 4 5 B. 1 2 3 4 5 C. 11 12 13 14 15 D. 11 12 3 4 5 109、西面关于数组的叙述中,正确的是() A. 数组必须先定义,然后使用 B. 定义数组时,可不加类型说明符

C. 定义数组后,可通过赋值运算符“=”对该数组名直接赋值 D. 在数据类型中,数组属于基本类型 110、一下程序段的运行结果是()

int i=0,a[]={6,5,3,7}; do {

a[i]++;

}while(a[i]<4);

for(i=0;i<4;i++) printf(\"%d\

A. 6537 B. 7563 C. 7537 D. 5673 111、有如下程序段:

int t[][3]={1,2,3,4,5,6,7,8,9,10,11,12}; printf(\"%d\\n\

则执行该程序段后输出结果是() A. 8 B. 7 C. 4 D. 2 112、以下程序段运行后s的值是()

int a[3][3]={1,2,3,1,2,3,1,2,3}; int i,j,s=1;

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

for(j=i;j<3;j++) s*=a[i][j];

A. 18 B. 108 C. 2 D. 12

113、以下不能对二维数组arr进行正确初始化的语句是()

A. int arr[2][3]={0}; B. int arr[][3]={1,2,3,4,5}; C. int arr[2][3]={{1,2},{3,4},{5,6}}; D. int arr[2][3]={{1},{3,4,5}}; 114、若有定义:int a[3][4]={{1,2},{0},{1,2,3}};则a[1][1]的值为() A. 0 B. {1,2} C. 1 D. 3

115、若有定义:int a[3][3];则表达式&a[2][1]-a[0]的值为() A. 7 B. 8 C. 6 D. 9

116、若有定义:int i=0,x=0;int a[3][3]={1,2,3,4,5,6,7,8,9};则以下程序段运行后x的值为()

for(;i<3;i++) x+=a[i][2-i];

A. 0 B. 12 C. 15 D. 18

117、若有定义int a[2][3];则对数组元素的非法引用的是() A. a[0][1/2] B. a[1][1] C. a[4-4][0] D. a[0][3] 118、以下数组定义中,正确的是()

A. int a[2][]={1,2,3,4,5}; B. int a[][2]={{0},{}}; C. int a[2][2]={{1,2},{3}}; D. int a[][]={1,2,3,4};

11

119、若有定义int a[][3]={1,2,3,4,5,6,7,8,9};则表达式sizeof(a)/sizeof(a[0])的值为() A. 3 B. 4 C. 5 D. 9 120、以下程序段运行后s的值是()

int a[3][3]={1,2,3,4,5,1,2,3,4}; int i,j,s=1;

for(i=0;i<3;i++) for(j=i+1;j<3;j++) s*=a[i][j];

A. 6 B. 120 C. 24 D. 480

121、设已定义:int a[][4]={0,0};则下列描述错误的是()

A. 数组a的每个元素都可得到初值0 B. 二维数组a的第一维大小为1 C. 数组a的行数为1

D. 只有元素a[0][0]和a[0][1]可得到初值0,其余元素均得不到初值0

122、设已定义:char str1[10],str2[10]=”Fujian”;则能将字符串”Fujian”赋给数组str1的正确语句是()

A. str1=”Fujian” B. strcpy(str1,str2); C. strcpy(str2,str1); D. str1=str2; 123、有如下定义:char str[3][2]={ 'a','b','c','\\0','e','f'};则语句:printf(\"%s\的输出结果是()

A. ab B. abcef C. abc\\0 D. abc

124、设有如下数组定义:char str[8]={ \"Fujian\则分配给数组str的存储空间是()字节 A. 6 B. 7 C. 8 D. 9

125、若有定义:char a[]=\"abcdef\";char b[]=\"xyz\";则以下程序段运行后屏幕输出为()

strcpy(a,b);

printf(\"%c\

A. c B. z C. \\0 D. d 126、以下程序段运行后屏幕输出为()

char a[]=\"abc\\0mis\"; printf(\"%d\

A. 5 B. 8 C. 3 D. 4

127、若有定义:int a=2;则语句a=strcmp(\"miss\运行后a的值为() A. 1 B. 0 C. -1 D. 2

128、以下对C语言字符数组描述中,正确的是() A. 可以用length函数计算字符数组中字符串的长度

B. 可以在赋值语句中通过赋值运算符\"=\"对字符数组整体赋值 C. 存放在字符数组中的字符串,以‟\\0‟作为该字符串结束标志 D. 字符数组只能存放字符串,不能存放字符 129、以下程序段运行后屏幕输出为()

char str[80];

strcpy(str, \"hello\"); printf(\"%d\

A. 5 B. 6 C. 7 D. 80

130、若有定义:char str1[6]= \"abcdm\则()是正确的 A. strcpy(str1,str2); B. 表达式strcmp(str1,str2)的值大于0 C. str1=str2; D. 表达式strlen(str1)的值为6

12

131、已有定义:char str1[15]={“university”},str2[15];则以下语句中正确的是()

A. str2=str1; B. str2=”college”; C. scanf(“%s”,&str2); D. printf(“%s”,str1); 132、设已定义:char s1[20]=”You are”,s2[9]=”welcome!”;若要形成字符串”You are welcome!”,正确的语句是()

A. strcat(s1,s2); B. strcpy(s1,s2); C. s1+s2; D. s1&s2

函数

133、在 C语言中,数组名作为函数调用的实参时,传递给形参的是() A. 数组元素的个数 B. 数组的第一个元素值 C. 数组中全部元素的值 D. 数组的首地址 134、以下程序的运行结果是()

int fun(int array[4][4]) {

int j;

for(j=0;j<4;j++) printf(\"%2d \printf(\"\\n \"); }

main() {

int a[4][4]={0,1,2,0,1,0,0,4,2,0,0,5,0,4,5,0}; fun(a); }

A. 2 0 0 5 B. 1 0 0 4 C. 0 1 2 0 D. 0 4 5 0

135、C语言允许函数值类型缺省定义,此时该函数值隐含的类型是() A. float型 B. long型 C. int型 D. double型 136、以下程序运行后屏幕输出为()

#include int f(int x,int y) {

return(x+y); }

main() {

int a=2,b=3,c; c=f(a,b);

printf(\"%d+%d=%d\\n \}

A. 0 B. 2+3=5 C. 2+3=0 D. 3+2=5 137、以下程序运行后屏幕输出为()

#include int a=2,b=3;

int max(int a,int b) {

13

int c;

c=a>b?a:b; return(c); }

main() {

int a=4;

printf(\"%d \}

A. 3,2 B. 2 C. 3 D. 4 138、以下程序的运行结果是()

fun(int i) {

int a=2; a=i++;

printf(\"%d \}

main() {

int a=5,c=3; fun(c);

printf(\"%d\}

A. 4 5 B. 3 5 C. 4 4 139、若有如下函数定义:

int fun() {

static int k=0; return ++k; }

以下程序段运行后屏幕输出为() int i;

for(i=1;i<=5;i++) fun(); printf(\"%d\

A. 0 B. 1 C. 5 D. 6 140、下面程序的输出结果是:()

#include int global=100; fun() {

int global=5; return ++global; }

void main()

D. 3 3 14

{

printf(\"%d\\n\}

A. 100 B. 101 C. 5 D. 6

141、下列关于C语言函数的描述中,正确的是() A. 函数的定义可以嵌套,但函数的调用不可以嵌套 B. 函数的定义不可以嵌套,但函数的调用可以嵌套 C. 函数的定义和函数的调用都可以嵌套 D. 函数的定义和函数的调用都不可以嵌套 142、以下程序的运行结果是()

fun(int x,int y) {

int z;

z=(xmain() {

int a=10,b=6;

printf(\"%d\\n\}

A. 4 B. 6 C. 10 143、以下程序运行结果是()

void main() {

int min(float x,float y); float a=-7.9,b=-6.3; int c;

c=min(a,b);

printf(\"%d\\n\}

int min(float x,float y) {

float z;

if(x>y) z=y; else z=x; return(z); }

A. -7.9 B. -7 C. -6.3 144、以下程序的运行结果是()

#define M(a,b) a*b main() {

int x=3,y=2,s1,s2;

D. 6 D. -6 15

s1=M(x+y,x-y); s2=M(x-y,x+y);

printf(\"%d,%d\\n\}

A. -1,7 B. 5,5 C. 7,-1 D. 5,-5 145、以下叙述中,正确的是()

A. “#define PRICE=30”定义了与30等价的符号常量PRICE B. 预编译处理命令行都必须以“#”开头

C. 程序中使用带参的宏时,参数类型要与宏定义时一致 D. 宏名只能包含大写字母和数字字符 146、以下叙述中,正确的是()

A. 宏展开不占用运行空间,只占用编译时间 B. 预编译处理命令行必须以分号结束

C. 一个源程序只能有一个预编译处理命令行

D. 使用带参数的宏定义时,应该说明每个参数的数据类型 147、以下的叙述中不正确的是()

A. 宏展开不占用运行时间,只占用编译时间 B. 宏名无类型

C. 宏名必须用大写字母表示 D. 预处理命令行都必须以#号开始 148、若有定义:#define PI 3,在表达式PI*2*2的值为() A. 12 B. 4 C. 3 D. 不确定 149、以下程序运行后,屏幕输出为()

#define MIN(a,b) ((a)<(b)?(a):(b)) main() {

int x=2,y=3,z; z=2*MIN(x,y); printf(\"%d\}

A. 2 B. 3 C. 4 D. 6 150、下列#include命令中,正确的是()

A. #inclue [string.h] B. #include {string.h} C. #include (string.h) D. #include 151、下面程序的输出结果是() #include #define ONE 1

#define TWO ONE+1 #define THREE TWO+1 void main () {

printf(\"%d\\n\}

A. 产生错误 B. 1 C. 2 D. 3 152、以下叙述中正确的是()

A. 预处理命令行必须位于C源程序的起始位置

16

B. 在C语言中,预处理命令行都以”#”开头

C. 每个C程序必须在开头包含预处理命令行:#include D. C语言的预处理只能实现宏定义和条件编译的功能 153、以下程序的运行结果是() #define ADD(x) x+x

main() {

int m=1,n=2,k; k=ADD(m+n)*3; printf(\"%d\}

A. 9 B. 10 C. 12 D. 18 1、下面程序的运行结果是()

#define M 10 #define S(x) x*x #define F(x) (x*x) main() {

int n1,n2;

n1=1000/S(M); n2=1000/F(M);

printf(\"%d,%d\\n\}

A. 10,10 B. 1000,10 C. 10,1000 D. 1000,1000

指针

155、设有以下语句,则()是对a数组元素的不正确引用,其中0<=i<10。 int a[10]={0,1,2,3,4,5,6,7,8,9},*p=a;

A. a[p-a] B. *(&a[i]) C. p[i] D. *(*(a+i))

156、若有定义int *p1,*p2;则指针变量p1、p2不能进行运算的是() A. < B. = C. + D. -

157、以下关于指针概念的叙述中,错误的是()

A. 一个指针变量只能指向同一类型的变量 B. 一个变量的地址称为该变量的指针C. 两个同类型的指针变量可以作加减运算 D. 任何指针变量都可以与空指针NULL进行比较 158、以下程序段运行后*(p+3)的值为()

char a[]=”good”; char *p; p=a;

A. „d‟ B. „\\0‟ C. 存放‟d‟的地址 D. „0‟ 159、以下程序段运行后*(++p)的值为()

char a[5]=”work”; char *p;

17

p=a;

A. „w‟ B. 存放‟w‟的地址 C. ‟o‟ D. 存放‟o‟的地址 160、若有定义:int *p,a=4;p=&a;则以下均代表地址的是() A. a,p B. &a,p C. &a,*p D. a,*p

161、若有说明语句:double *p,a;则能通过scanf语句正确给输入项读入数据的程序段是() A. *p=&a;scanf(“%lf”,p); B. *p=&a;scanf(“%lf”,*p); C. p=&a,scanf(“%lf”,*p); D. p=&a;scanf(“%lf”,p);

162、若已定义:int x=12;对①int *p=&x;和②*p=x;这两条语句的正确理解是()

A. 语句①是在对指针变量p定义时初始化,使p指向x;而语句②是将变量x的值赋给指针变量p所指向的变量

B. 语句①和②中的*p含义相同,都表示给指针变量赋值

C. 语句①是在对指针变量p定义时初始化,使p指向x;而语句②是将变量x的值赋给指针变量p

D. 语句①和②的执行结果都是把变量x的地址赋给指针变量p 163、下面语句正确的是()

A. int *p;*p=20 B. char *s=”abcdef”;printf(“%s\\n”,s);

C. char str[]=”abcd”;str++; D. char str[]={„a‟,‟b‟,‟c‟};printf(“%s”,str); 1、若有定义int a[2][3],*p=a[0];则以下不能表示数组元素a[1][2]的是() A. *(a[1]+2) B. *(p[1]+2) C. p[5] D. *(p+5) 165、若已定义:int a=5,*p;且p=&a;则以下表示中不正确的是()

A. &(*p)==&a B. *(&a)==a C. &(*p)==p D. *(p++)==a++

166、若有以下程序段,其中0<=i<4,0<=j<3,则不能正确访问a数组元素的是()

int i,j,(*p)[3];

int a[][3]={1,2,3,4,5,6,7,8,9,10,11,12}; p=a;

A. *(*(a+i)+j) B. p[i][j] C. (*(p+i))[j] D. p[i]+j 167、以下程序段的运行结果是()

int x[]={2,3,4,5,6,7},*p=x; int i,s=0;

for(i=1;i<6;i++) s+=p[i++]; printf(\"%d\

A. 12 B. 15 C. 25 D. 27 168、下面程序的运行结果是()

main() {

int x=36,y=63; int *p,*q,*t; p=&x;q=&y; t=p; p=q; q=t;

printf(\"%d,%d\\n\}

A. 36,36 B. 63,63 C. 36,63 D. 63,36

18

169、以下程序段运行后x的值为()

int a[]={1,2,3,4,5,6,7}; int i,x,*p; x=1; p=&a[2];

for(i=0;i<3;i++) x*=*(p+i);

A. 不确定 B. 24 C. 120 D. 60 170、以下程序段运行后x的值为()

int a[]={1,2,3},b[]={4,2,5}; int *p,*q; int i,x; p=a;q=b;

for(i=0;i<3;i++) if(*(p+i)==*(q+i)) x=*(p+i)*2;

A. 2 B. 4 C. 5 171、以下程序运行结果是()

main() {

char a[]=\"1357\ for(p=a;pA. 1357 B. 1357357577 172、下面程序的输出结果是()#include void main() {

int i;

char *s=\"abc\"; for(i=0;i<3;i++)

printf(\"%s\\n\}

A. abc bc c B. c bc abc C. abc c bc

D. 不确定 C. 7531 D. 7531531311 19

D. a ab abc

173、下面程序的输出结果是()

#include void main() {

char *str=\"12345\ printf(\"%c\\n\}

A. 1 B. 2 C. 3 D. 错误

174、以下程序执行时,输入1 2 3 4 5<回车>,输出为() #include #define N 5 void main() {

int a[N]; int *p=a;

while(pscanf(\"%d\while(p>a)

printf(\"%d\}

A. 5 4 3 2 1 B. 1 2 3 4 5 C. 2 3 4 5 1 D. 4 3 2 1 5 175.以下程序段的运行结果是() int x[]={2,3,4,5,6,7},*p=x; int i,s=0;

for(i=1;i<6;i+=2)s+=*(p+i); printf(\"%d\A.27 B.25 C.12 D.15

176.以下程序运行结果() main() {

int a[]={9,8,7,6,5,4},*p,*q,i; p=a;q=p+5; for(i=0;i<6;i++)

printf(\"%d%d\}

A.948576675849 B.948576 C.495867 D.495867768594

结构体和共用体

177.以下程序段的运行结果() union

20

{

int num; char str[2]; }s;

s.num=20; s.str[0]='A'; s.str[1]='\\0';

printf(\"%d\A.20 B.65 C.0 D.A

178.定义一个结构体变量后,该变量所占内存大小是() A.结构体中第一个成员所需内存容量 B.结构体中最后一个成员所需内存容量

C.结构体中各成员所需内存容量总和 D.结构体成员中占内存容量最大者所需的容量 179.设有如下定义: union u_type { int x; float y; double z; char m; }a,b,c;

执行语句a.x=8;a.y=7.5;a.m='N';b.x=9;后,共用体变量a中的值为() A.9 B.'N' C.7.5 D.8 180.若有定义: struct teacher {

int num;

char name[10]; char sex; int age; float score; }teacher1;

则变量teacher1所占用的内存字节数是() A.5 B.14 C.19 D.20 181.下列对结构体类型变量定义不正确的是() A.struct teacher {

int num; int age; }teach1; B.struct {

int num; int age;

}teach1,teach2;

21

C.struct {

int num; int age; }teacher;

struct teacher teach1; D.struct teacher {

int num; int age; };

struct teacher teach1; 182.若有定义: struct teacher {

int num; char sex; int age; }teacher1;

则下列叙述不正确的是() A.struct是结构体类型的关键字

B.struct teacher是用户定义的结构体类型

C.num,sex,age都是结构体变量teacher1的成员D.teacher1是结构体类型名

183.以下程序的运行结果是() #include union Utype { int i; float f; }u[2];

void main() {

printf(\"%d\\n\}

A.2 B.4 C.6 D.8 184.以下程序的运行结果是() #include union Utype { int i; flaot f; }; struct

22

{

char ch[2]; int i;

union Utype u; }a;

void main() {

printf(\"%d\\n\}

A.5 B.6 C.7 D.8

185.以下C语言共用体类型数据的描述中,不正确的是()

A.共用体变量占的内存大小等于所需内存最大的成员所占的内存 B.共用体类型可以出现在结构体类型定义中

C.在定义共用体变量的同时允许对第一个成员的值进行初始化 D.同一共用体各成员的首地址不相同 186.设有如下语句: struct student {

int num; int age; };

struct student stu[3]={{101,18},{102,21},{103,19}}; struct student *p=stu;

则下面表达式的值为102的是()

A.(p++)->num B.(p++)->age C.(*p).age D.(*++p).num 187.根据下面定义,能打印出字母'H'的语句是() struct stu {

char name[8]; int age; };

struct stu class[12]={\"Wang\

A.printf(\"%c\\n\ B.printf(\"%c\\n\C.printf(\"%c\\n\ D.printf(\"%c\\n\

枚举、自定义类型和位运算

199.对枚举类型进行定义,不正确的是()。 A.enum b{1,2,3}; B.enum a{A,B,C};

C.enum c{D=3,E,F}; D.enum d{X=0,Y=5,Z=9}; 200.假定已有如下变量说明和枚举定义: char ch; int j,k;

enum day{sun,mon,tue,wed,thu,fri,sat}; int a[sat];

23

判断下列语句是否符合语法规则,结果是()。 sun=0; /*语句1*/ j=mon+tue; /*语句2*/

if(a[mon]>0)j++; /*语句3*/

A.语句1错误,语句2和语句3正确 B.语句2正确,语句1和语句3错误 C.语句3正确,语句1和语句2错误 D.语句1正确,语句2和语句3错误 201.设有如下定义: typedef int * INTEGER; INTEGER p,*q;

则()是正确的叙述。

A.p是int型变量 B.q是基类型为int的指针变量

C.p是基类型为int的指针变量 D.程序中可用INTEGER代替int类型名 202.在对无符号数的位运算中,操作数左移一位相当于()。

A.操作数除以2 B.操作数乘以2 C.操作数除以4 D.操作数乘以4 203.若有定义:int a=20,b=28,c;则执行语句c=(a^b)<<2;后c的值为()。 A.2 B.5 C.32 D.92

204.若有定义:int a=5,b=7,c;则执行语句c=a&b;后c的值为()。 A.12 B.2 C.6 D.5 205.下面程序的输出结果为()。 #include void main() {

enum Weekday{sun=7,mon=1,tue,wed,thu,fri,sat}; enum Weekday day=sat; printf(\"%d\\n\} A.7 B.6 C.5 D.4 206.若有以下类型说明,叙述正确的是()。 typedef struct {

int num; char *name; int score;

}STU,*PSTU; A.STU是变量名 B.PSTU是变量名

C.PSTU是指向结构体类型STU的指针类型名 D.类型说明语句有错误

207.下面程序段的运行结果是()。 int a=5,b=6; printf(\"%d\A.5 B.6 C.7 D.8 208.若有以下类型说明,则()是正确的叙述。 typedef union

24

{

char str[2]; int i; }sp;

A.sp是一个共用体变量名 B.sp是一个共用体类型名 C.union sp是共用体类型名

D.typedef union是共用体类型名 209.定义枚举类型的关键字是()。 A.define B.enum C.union

D.struct

文件

210.以下程序的功能是()。 #include main() {

FILE *fp; long int n;

fp=fopen(\"wj.txt\fseek(fp,0,SEEK_END); n=ftell(fp); fclose(fp);

printf(\"%ld\}

A.计算文件wj.txt的起始地址 B.计算文件wj.txt的终止地址 C.计算文件wj.txt内容的字节数 D.将文件指针定位到文件末尾 211.设有一文本文件test.txt,其内容为\"cprogram\"(不包含引号),以下程序段的运行结果是()。 FILE *fp; char *str;

if((fp=fopen(\"test.txt\ str=fgets(str,5,fp); printf(\"%s\

A.cpro B.cprog C.progr D.cprogram 212.在C语言程序中,对文件操作的一般步骤是()。 A.打开文件,定义文件指针,读写文件,关闭文件 B.定义文件指针,读文件,写文件,关闭文件 C.定义文件指针,打开文件,读写文件,关闭文件 D.操作文件,定义文件指针,修改文件,关闭文件 213.下面程序运行后的结果是()。 #include main() {

FILE *fp;int i=10,j=20,k,n;

25

fp=fopen(\"d_f.dat\fprintf(fp,\"%d\\n\fprintf(fp,\"%d\\n\fclose(fp);

fp=fopen(\"d_f.dat\fscanf(fp,\"%d%d\printf(\"%d %d\\n\fclose(fp); }

A.10 20 B.10 30 C.20 30 D.20 10

214.以下程序运行后,屏幕显示write ok!,下列说法正确的是()。 #include main() {

FILE *fp;

fp=fopen(\"data.txt\if(fp!=NULL) {

fprintf(fp,\"%s\\n\fclose(fp);

printf(\"write ok!\\n\"); } }

A.当前工作目录下存在data.txt文件,其中的内容为\"write ok!\" B.fclose(fp);语句的功能是打开文件

C.当前工作目录下一定不存在data.txt文件 D.当前工作目录下一定存在data.txt文件

215.以下程序运行后,屏幕显示File open error!,则可能的原因是()。#include main() {

FILE *fp; char str[256];

fp=fopen(\"test.txt\if(fp==NULL) {

printf(\"File open error!\"); return; }

fscanf(fp,\"%s\fclose(fp); }

A.当前工作目录下有test.txt文件,但test.txt文件太小 B.test.txt文件不能关闭

26

C.当前工作目录下没有test.txt文件

D.当前工作目录下有test.txt文件,但test.txt文件太小 216.以下程序的可执行文件名为cmdline.exe。 #include #include

void main(int argc,char *argv[]) {

if(argc!=2) {

printf(\"You forgot to type your name or you typed more parameters\\n\"); exit(1); }

printf(\"Hello %s\\n\}

在DOS命令行输入:cmdline harry<回车>,则输出结果是()。 A.You forgot to type your name or you typed more parameters B.Hello harry C.Hello cmdline D.Hello

217.对下面程序正确的描述是()。 #include #include void main() {

FILE *in,*out;

if((in=fopen(\"infile.txt\{

printf(\"cannot open infile\\n\"); exit(0); }

if((out=fopen(\"outfile.txt\{

printf(\"cannot open outfile\\n\"); exit(0); }

while(!feof(in))

fputc(fgetc(in),out); fclose(in); fclose(out); }

A.程序实现在屏幕上显示磁盘文件infile.txt的内容

B.程序实现将两个磁盘文件infile.txt和outfile.txt的内容合二为一 C.程序实现将磁盘文件infile.txt复制到磁盘文件outfile.txt D.程序实现将两个磁盘文件合并在屏幕上输出

27

218.以下叙述中正确的是()。

A.C语言中的文件是流式文件,因此只能顺序存取数据

B.打开一个已有的文件进行了写操作后,原有文件中的全部数据必定被覆盖

C.在一个程序中当对文件进行了写操作后,必须先关闭该文件然后再打开,才能读到第1个数据

D.当对文件的写操作完成之后,必须将它关闭,否则可能导致数据丢失 219.对下面程序正确的描述是()。 #include main() { int i;

FILE *fp;

if((fp=fopen(\"test.txt\",\"rb+\"))!=NULL) {i=fgetc(fp);i=i+1;} fseek(fp,0,SEEK_SET); fputc(i,fp); fclose(fp); }

A.将文件中第一个字节的内容加1并重新写入到第一个字节 B.将文件中第一个字节的内容加1并写入到第二个字节中 C.以只读方式打开文本文件test.txt D.以只读方式打开二进制文件test.dat

220.若在fopen函数中使用文件的方式是\"wb+\",该方式的含义是()。 A.为读/写打开一个文本文件 B.为输出打开一个文本文件

C.为读/写建立一个新的文本文件 D.为读/写建立一个新的二进制文件

第二部分:改错题(每小题10分,2小题/套)

说明如下:

(1)修改程序中每对\"/**/\"之间存在的错误; (2)不得删改程序中的\"/**/\"注释和其它代码;

(3)源程序均在考生文件夹中,务必以原文件名保存程序;

(4)按alt+tab键,切换考试程序与Turbo C;按alt+enter键,切换Turbo C窗口大小。 第1套

1.程序Cmody011.c的功能是:从字符串数组str1中取出ACSII码值为偶数且下标为偶数的字符依次存放到字符串t中。

例如,若str1所指的字符串为:4AZ18c?Ge9a0z! 则t所指的字符为:4Z8z 注意:数组下标从0开始。

2.程序Cmody012.c中,函数fun(int n)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。例如:

-------------------------Cmody011.c-------------------

28

#include #include #include #include void main() {

char str1[100],t[200]; int i,j;

/**/i=0;/**/ clrscr();

strcpy(str1,\"4AZ18c?Ge9a0z!\"); for(i=0;i/**/if((str1[i]%2==0)&&(i%2!=0))/**/ {

t[j]=str1[i]; j++; } }

t[j]='\\0';

printf(\"\\nOriginal string:%s\\n\printf(\"\\n Result string:%s\\n\}

-------------------------Cmody012.c------------------- #include #include #include #include #define M 50 double fun(int n) {

double y=0.0; int i,j; j=0;

for(i=1;;i++) {

/**/if((i<10)&&(i%3==0))/**/ {

/**/y+=1/i;/**/ j++; }

if(j==n)break; }

return y;

29

}

void main() {

clrscr();

printf(\"fun(8)=%8.3lf\\n\}

第2套

1.程序Cmody021.c输出如下所示图形: * *** ***** ******* *********

2.程序Cmody022.c的功能是求解百元买百鸡问题:

设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案? -------------------------Cmody021.c------------------- #include void main() {

/**/int i;j;/**/ for(i=1;i<=5;i++) {

for(j=1;j<=5-i;j++)printf(\" \"); /**/ for(j=1;j<=5;j++)/**/ printf(\"*\"); printf(\"\\n\"); } }

-------------------------Cmody022.c------------------- #include #include /**/int fun();/**/ {

int hen,cock,chicken,n=0; clrscr();

for(cock=0;cock<=50;cock+=1) for(hen=0;hen<=100;hen=hen+1) {

chicken=2*(100-hen-2*cock); /**/if(cock+hen+chicken=100)/**/ {

n++;

printf(\"%d-->hen:%d,cock:%d,chicken:%d\\n\

30

if(n==20)getch(); } } return n; }

void main() {

int num; num=fun();

printf(\"\\nThere are %d solutions.\\n\getch(); }

第3套

1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符(+、-、*、/或%),进行相应的运算后输出运算的结果。 如输入:1+2 将输出:1+2=3

2.程序Cmody032.c的功能是:输出201-300之间的所有素数,统计总个数。 -------------------------Cmody031.c------------------- #include #include void main() {

int m,n,result,flag=0; /**/char ch,/**/ clrscr();

printf(\"Input an expression:\"); scanf(\"%d%c%d\/**/switch ch/**/ {

case '+':result=m+n;break; case '-':result=m-n;break; case '*':result=m*n;break; case '%':result=m%n;break; case '/':result=m/n;break;

default:{printf(\"Error!\\n\");flag=1;} }

if(!flag)printf(\"%d%c%d=%d\\n\getch(); }

-------------------------Cmody032.c------------------- #include #include void main()

31

{

int num; printf(\"\\n\"); num=fun();

printf(\"\\nThe total of prime is %d\getch(); }

int fun() {

int m,i,k,n=0;

for(m=201;m<=300;m++) {

k=sqrt(m+1); for(i=2;i<=k;i++) /**/if(m/i==0)/**/ break;

/**/if(i==k)/**/ {

printf(\"%-4d\n++;

if(n%10==0)printf(\"\\n\"); } }

return n; }

第四套

1.程序Cmody041.c,其功能是统计输入字符串中小写英文字母的个数。如 输入:abcdEFGHIJK123 输出:4

2.程序Cmody042.c,其功能是将从键盘依次输入的M个整数逆序输出。-------------------------Cmody041.c------------------- #include #include main() {

char str1[128];

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

len=strlen(str1); for(i=0;i/**/if(str1[i]>='a'||str1[i]<='z')/**/ sum++; }

32

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

-------------------------Cmody042.c------------------- #include #include #define M 8 main() {

int a[M],i;

printf(\"Please input 8 numbers:\\n\"); for(i=0;iscanf(\"%d\printf(\"Inverge order is:\\n\"); /**/for(i=M-1;i<=0;i--)/**/ printf(\"%d \printf(\"\\n\"); getch(); }

第5套

1.程序Cmody051.c,其功能是统计输入字符串中大写英文字母的个数。 如 输入:abcDEFGH123 输出:5

2.程序Cmody052.c,其功能是实现从键盘依次输入M个整数,输出其中所有的偶数。如 输入:23 62 38 45 26 输出:62 38 26

-------------------------Cmody051.c------------------- #include #include main() {

/**/char str1/**/ int i,len,sum=0;

printf(\"Please input a string:\\n\"); scanf(\"%s\len=strlen(str1); for(i=0;iif(str1[i]>='A'&&str1[i]<='Z') /**/sum--;/**/ }

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

33

-------------------------Cmody052.c------------------- #include #include /**/#include M 5/**/ main() {

int a[M],i;

printf(\"Please input 5 numbers:\\n\"); for(i=0;iprintf(\"Even numbers:\\n\"); for(i=0;i第6套

1.程序Cmody061.c,其功能是将字符串中'0'-'8'的数字字符变为比它大1的数字字符,将'9'变为'0'。

如 输入:abc12cd56EFGH4 输出:abc23cd67EF90GH5

2.程序Cmody062.c,其功能是将程序中的两个字符串\"ABC\"、\"xyz\"连接在一起,并输出\"ABCxyz\"。

-------------------------Cmody061.c------------------- #include #include main() {

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

len=strlen(str1);

/**/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';/**/ puts(str2); getch();

34

}

-------------------------Cmody062.c------------------- #include #include void main() {

char s1[12]=\"ABC\char *ps1=s1,*ps2; /**/ps2=NULL;/**/

/**/while(*ps1==NULL)/**/ ps1++;

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

第7套

1.程序Cmody071.c,其功能是从键盘输入三角形的三边长,求其面积,若三个边长不能构成三角形,则提示。 如 输入:6 9 11 输出:26.98

2.程序Cmody072.c,其功能是求解百马百担问题。

有100匹马,驮100担货,大马驮3担,中马驮2担,两匹小马驮1担,问大、中、小马数可分别为多少?有多少种解决方案?

-------------------------Cmody071.c------------------- #include #include void main() {

float a[3],s,area; int i;

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

scanf(\"%f\

/**/if(a[0]+a[1]>a[2]||a[1]+a[2]>a[0]||a[0]+a[2]>a[1])/**/ {

s=(a[0]+a[1]+a[2])/2;

area=sqrt(s*(s-a[0])*(s-a[1])*(s-a[2])); printf(\"area is %.2f\\n\} else

printf(\"error.\\n\"); getch(); }

-------------------------Cmody072.c-------------------

35

#include #include /**/void fun()/**/ {

int large,middle,small,n=0; clrscr();

for(large=0;large<=33;large++)

for(middle=0;middle<=50;middle++) {

small=2*(100-3*large-2*middle); /**/if(large+middle+small=100)/**/ { n++;

printf(\"%d-->large:%d,middle:%d,small:%d\\n\} }

return n; }

void main() {

int num; num=fun();

printf(\"\\nThere are %d solutions.\\n\getch(); }

第8套

1.程序Cmody081.c,其功能是求一堆零件的总数(100到200之间)。

如果分成4个零件一组的若干组,则多2个零件;若分成7个零件一组,则多3个零件;若分成9个零件一组,则多5个零件。

2.程序Cmody082.c,其功能是交换连个变量的值。 如 输入:Original:a=2 b=3 输出:Result:a=3 b=2

-------------------------Cmody081.c------------------- #include void main() { int i;

/**/for(i=100;i<200;i++);/**/ if((i-2)%4==0) if(!((i-3)%7)) if(i%9==5)

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

36

-------------------------Cmody082.c------------------- #include

/**/void swap(int p1,int p2)/**/ {

int temp; temp=*p1; /**/p1=p2;/**/ *p2=temp; }

void main() {

int a,b;

printf(\"please input 2 numbers:\\n\"); scanf(\"%d%d\

printf(\"\\nOriginal:a=%d b=%d\\n\swap(&a,&b);

printf(\"\\nResult:a=%d b=%d\\n\getch(); }

第9套

1.程序Cmody091.C,其功能是计算1至100之间的奇数之和,偶数之和。 2.程序Cmody092.C的功能是求满足等式xyz+yzz=520的x,y,z值(其中xyz和yzz分别表示一个三位数)。

-------Cmody091.C--------------------------------------------------------------------------- #include void main() {

int b,i;

/**/int a=c=0; /**/

/**/for(i=0,i<=100,i+=2)/**/ {

a+=i; b=i+1; c+=b; }

printf(\"total of even numbers:%d\\n\ printf(\"total of odd numbers:%d\\n\ getch(); }

-------Cmody092.C--------------------------------------------------------------------------- #include void main() {

37

int x,y,z,i,result=520; for(x=1;x<10;x++) for(y=1;y<10;y++)

/**/for(z=1;z<10;z++)/**/ {

i=100*x+10*y+z+100*y+10*z+z; /**/if(i=result) /**/

printf(\"x=%d,y=%d,x=%d\\n\ } getch(); }

第10套

1.程序Cmody101.c,其功能是计算如下所示的数学表达式:

a22.3a5.6b22.3b5.6c22.3c5.6 s

a8.2b8.2c8.22.程序Cmody102.c,其功能是实现打印出所有的“水仙花数”。所谓“水仙花数”是指一个

三位数,其各位数字立方和等于该数本身。例如,153是一个水仙花数,因为153=13+53+33。 -------Cmody101.C--------------------------------------------------------------------------- #include

#define F(x) (x*x-2.3*x+5.6)/(x+8.2) void main() {

float a=6.0,b=3.0,c; /**/int s;/**/

printf(\"\\nPlease input c: \"); scanf(\"%f\/**/ s=F(a,b,c); /**/ printf(\"\\ns=%.2f\\n,s\"); getch(); }

-------Cmody102.C--------------------------------------------------------------------------- void main() {

int f,s,t,n;

printf(\"\\nThe list is:\\n\"); for(n=100;n<1000;n++) {

f=n%10;

s=(n%100)/10; /**/t=n%100;/**/

/**/if(t*t*t+s*s*s+f*f*f=n)/**/ printf(\"%d \

38

}

printf(\"\\n\"); getch(); }

第11套

1.程序Cmody111.C,输出如下所示图形: @ @@ @@@ @@@@ @@@@@ @@@@@@

2.程序Cmody112.C,实现输出如下所示的4×4的矩阵: 1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13

-------Cmody111.C--------------------------------------------------------------------------- #include #include void main() {

/**/int i;j; /**/

/**/for(i=6;i>1;i--)/**/ {

printf(\"@\");

for(j=1;j<=6-i;j++) printf(\"@\"); printf(/**/\"\\r\"/**/); }

getch(); }

-------Cmody112.C---------------------------------------------------------------------------

P页缺。。。。。

程序填空题 第1套

1.补充程序Ccon011.C,使其计算f(x)x2x21。 -------Ccon011.C--------------------------------------------------------------------------- #include

39

#include void main() {

int x;

/**/ /**/

printf(\"Input an integer: \"); scanf(\"%d\

f = /**/ /**/ ; printf(\"F(x)=%f\\n\}

(12.补充程序Ccon012.C,该程序中用公式41111)计算圆周率35710001的近似值。

-------Ccon012.C--------------------------------------------------------------------------- #include void main() { double pi=0; long i, sign=1;

for(i=1;i<=10001;i+=2) {

pi+=1.0*sign/i;

sign=/**/ /**/; }

pi*=/**/ /**/; printf(\"%f\\n\}

3. 补充程序Ccon013.c,程序实现从10个数中找出最大值和最小值。

-------Ccon013.C--------------------------------------------------------------------------- #include #include int max,min;

void find_max_min(int *p,int n) {

int *q;

max=min=*p;

for(q=p; q*q) min=*q; }

void main() {

int i,num[10];

printf(\"Input 10 numbers: \");

40

for(i=0;i<10;i++) scanf(\"%d\ find_max_min(/**/ /**/,10); printf(\"max=%d,min=%d\\n\ }

第2套

1.补充程序Ccon021.C,使其满足下式的一位整数A和B的值。

-------Ccon021.C--------------------------------------------------------------------------- #include void main() {

int a,b,k;

int plu = /**/ /**/ for(a=1; a<10; a++) for(b=1; b<10; b++) {

k = (a*10+b) * /**/ /**/ ;

if(k==plu) printf(\"A = %d, B = %d\\n\ } }

2.补充程序Ccon022.C,使其实现输入若干整数,统计其中大于零和小于零的个数,输入零结束。

-------Ccon022.C--------------------------------------------------------------------------- #include void main() {

int n,a,b;

/**/ /**/ scanf(\"%d\

while(/**/ /**/) {

if(n>0) a++;

else /**/ /**/ scanf(\"%d\ }

printf(\"Positive integer: %d, negative integer: %d\\n\}

3.补充程序Ccon023.c,该程序可测试歌德猜想:从键盘上输入一个大于6的偶数,总能找到两个素数,使得这两个素数之和正好等于该偶数。

41

-------Ccon023.C--------------------------------------------------------------------------- #include #include int prime(int n) { int k,flag=1;

for(k=2; k<=n/2+1; k++)

if (n%k==0) { flag=/**/ /**/ ; break;} return flag; }

void main() { int num, a; clrscr(); do

{ printf(\"Please input an even number:\"); scanf(\"%d\

}while(num<=6||num%2==1); for(a=2;a<=num/2+1;a++)

if(prime(a) && prime(/**/ /**/)) printf(\"\\n %d = %d + %d \}

第3套

1.补充程序Ccon031.C,使其用牛顿迭代法求方程2x3-4x2+3x-6=0在1.5附近的根。 -------Ccon031.C--------------------------------------------------------------------------- #include #include /**/ /**/ { float x,x0,f,f1; x=1.5; do

{ x0=x;

f=((2*x0-4)*x0+3)*x0-6; f1=(6*x0-8)*x0+3; x=x0-f/f1;

}/**/ /**/(fabs(x-x0)>=1e-6); printf(\"the root is: %.2f\\n\}

2.补充程序Ccon032.C,该程序的功能是输出的一行字符中的大写字母转变为相应的小写字母,小写字母则转变为相应的大写字母,其余字符不变。

-------Ccon032.C--------------------------------------------------------------------------- #include void main() { char s[80]; int i;

42

printf(\"Please input a string: \");

for(i=0;((s[i]=getchar())!='\\n')&&(i<80);i++); s[i]='\\0';

for(i=0;s[i]!='\\0';/**/ /**/) {

if(s[i]>='a'&&s[i]<='z') s[i]=s[i]-32;

else if(/**/ /**/) s[i]=s[i]+32; printf(\"%c\ } }

3.补充程序Ccon033.c,其中main函数通过调用average函数计算数组元素的平均值。 -------Ccon033.C--------------------------------------------------------------------------- #include

float average(int *pa,int n) {

int k;

/**/ /**/ for(k=0;kavg = avg+/**/ /**/; avg = avg/n; return avg; }

void main()

{ int a[5]={20,30,45,,23}; float m;

m=average(/**/ /**/, 5); printf(\"Average=%f\\n\}

第4套

1.补充程序Ccon041.C,使其实现从键盘输入一个同学的姓名(如“Jack”),输出问候该同学的信息(如“Hello,Jack!”)。

-------Ccon041.C--------------------------------------------------------------------------- /**/ /**/ main() {

/**/ /**/ str[11];

printf(\"Please input a name:\\n\"); scanf(\"%s\

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

43

2.补充程序Ccon042.C,使程序中的sort()函数用冒泡法对数组a中的m个元素从大到小排序。

-------Ccon042.C--------------------------------------------------------------------------- #include #include void sort(int a[],int m) { int i,j,t,swap;

for(i=0;iswap=0;

for(j=0;jif/**/ /**/ {

swap=1; t=a[j];

a[j]=/**/ /**/; 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;iprintf(\"%d \ printf(\"\\n\"); getch(); }

3.补充程序Ccon043.C,使程序中的fun()函数能用勾股定理判断一个三角形是否为直角三角形,即输入一个三角形的三边长a,b,c。若能构成直角三角形则返回1,不能则返回0。 -------Ccon043.C--------------------------------------------------------------------------- #include #include

int fun(/**/ /**/) {

float temp; int bTrue=0; if(a44

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

main() {

float a,b,c;

printf(\"Please input three numbers:\\n\"); scanf(\"%f%f%f\ if(fun(a,b,c)==1) printf(\"Yes\\n\"); else

printf(\"No\\n\"); getch(); }

第5套

1.补充程序Ccon051.C,使其实现从键盘输入一个整数,输出该数的平方。 -------Ccon051.C--------------------------------------------------------------------------- #include main() {

int x;

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

printf(\"%d*%d=%d\\n\ /**/); getch(); }

2.补充程序Ccon052.C,使程序中的sort()函数用选择法对数组a中的m个元素从大到小排序。

-------Ccon052.C--------------------------------------------------------------------------- #include #include void sort(int a[],int m) { int i,j,k,t;

for(i=0;i45

k=i;

for(j=i+1;jif(a[j]a[i]=/**/ /**/; } } }

void main() {

int a[]={72,25,58,32,2,15,7,}; int i,m=sizeof(a)/sizeof(int); sort(a,m);

for(i=0;iprintf(\"%d \ printf(\"\\n\"); getch(); }

3.补充程序Ccon053.C,使程序中的fun()函数能三角形三边长a,b,c,用公式

s(sa)(sb)(sc),s(abc)/2计算这个三角形的面积(规定:若这三条边不

能构成三角形,返回-1)。

-------Ccon053.C--------------------------------------------------------------------------- #include #include

/**/ /**/ fun(float a,float b,float c) {

float s,area;

s=/**/ /**/; s=s*(s-a)*(s-b)*(s-c); if (s<0)

area=-1; else

area=sqrt(s); return area; }

main() {

float a,b,c,area;

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

46

printf(\"Area is:%.2f\\n\ getch(); }

第6套

1.补充程序Ccon061.C,使其从键盘输入一个4行4列的二维整型数组表示4×4阶矩阵,并计算第1列元素之和。 如 输入:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

输出:28

-------Ccon061.C--------------------------------------------------------------------------- #include #include main() {

int i,/**/ /**/; int a[4][4],sum; sum=/**/ /**/;

printf(\"Please input 16 numbers:\\n\"); for(i=0;i<4;i++) for(j=0;j<4;j++)

scanf(\"%d\ for(i=0;i<4;i++)

/**/ /**/ printf(\"%d\\n\ getch(); }

2.补充程序Ccon062.C,使程序中的fun()函数用二分法在按从小到大排好序的数组a中查找q,若找到第一个q则返回对应的下标,没找到返回-1。

-------Ccon062.C--------------------------------------------------------------------------- #include

int fun(int a[],int n,/**/ /**/) {

int left,right,mid; left=0; right=n-1;

while(left<=right)

{ mid=/**/ /**/; if(qa[mid]) left=mid+1; else return mid; }

return -1;

47

}

main()

{int a[]={3,4,6,11,17,22,31,45}; int k,n;

n=sizeof(a)/sizeof(int); k=fun(a,n,31); printf(\"%d\\n\ getch();

3.补充程序Ccon063.C,使其中的fun()函数判断输入的一个点(x,y)是否位于坐标在原点,半径为r(r>0)的圆内。

-------Ccon063.C--------------------------------------------------------------------------- #include #include

int fun(/**/ /**/,float x,float y) {

int bIn;

bIn=/**/ /**/main() {

float r=-1,x,y; int bIn; while(r<0)

{ printf(\"Please input radius r(r>0):\\n\"); scanf(\"%f\ }

printf(\"Please input three dot(x,y):\\n\"); scanf(\"%f%f\ bIn=fun(r,x,y); if(bIn==1)

printf(\"in the circle!\\n\"); else

printf(\"out of the circle!\\n\"); getch(); }

第7套

21.补充程序Ccon071.C,对函数f(x)x2x6,分别计算f(x8)和f(sinx)的值。

如x=2.0,则输出: f(x8)86.00 0f(sinx)5.008

48

-------Ccon071.C--------------------------------------------------------------------------- #include

/**/ /**/ double fun(double x) {

/**/ /**/ }

main() {

double x,y1,y2; clrscr();

printf(\"Please input x:\"); scanf(\"%lf\ y1=fun(x+8);

y2=fun(/**/ /**/); printf(\"\\nf(x+8)=%.3lf\ printf(\"\\nf(sinx)=%.3lf\ getch(); }

2.补充程序Ccon072.C,计算pm!n!(mn)!,其中m,n为整数且mn0。-------Ccon072.C--------------------------------------------------------------------------- #include

double fun(unsigned m,unsigned n) {

unsigned i; double p=1.0; for(i=1;i<=m;i++) /**/ /**/ for(i=1;i<=n;i++)

/**/ /**/ for(i=1;i<=m-n;i++) p=p/i; return p; }

void main() {

clrscr();

printf(\"p=%f\\n\ getch(); }

3.补充程序Ccon073.C,函数findmax返回数组中的最大元素。

-------Ccon073.C---------------------------------------------------------------------------

49

#include

int findmax(int* array,int size);

void main() {

int a[]={33,91,23,45,56,-12,32,12,5,90}; clrscr();

printf(\"The max is %d\\n\ /**/); getch(); }

int findmax(int *array,int size) {

int i,/**/ /**/; for(i=1;iif(array[i]>max) max=array[i]; return max; }

第8套

m1.补充程序Ccon081.C,根据输入的整数m(m>=0)值,计算

i。

i1-------Ccon081.C--------------------------------------------------------------------------- #include

unsigned sum(unsigned n) {

unsigned i,/**/ /**/ for(i=1;i<=n;i++) sum+=i;

/**/ /**/ }

void main() {

int m; clrscr();

printf(\"Please input a unsigned integer:\"); scanf(\"%d\ while(m<0){

printf(\"Please input a unsigned integer:\"); scanf(\"%d,&m\"); }

printf(\"\\nThe sum is %d\\n\ /**/); getch(); }

2.补充程序Ccon082.C,使其实现将一个字符串str的内容反向存储。

50

-------Ccon082.C--------------------------------------------------------------------------- #include #include void main() {

int i,j;

char str[]=\"1234567\ /**/;

for(i=0,/**/ /**/;ik=str[i]; str[i]=str[j]; str[j]=k; }

clrscr();

printf(\"%s\\n\ getch(); }

3.补充程序Ccon083.C,实现将结构体数组mystudent中存储的各学生信息按其学号的升序排列。

-------Ccon083.C--------------------------------------------------------------------------- #include #include typedef struct{ int num;

char name[20],sex[2]; int age,score; }STU;

STU mystudent[]={

{1111,\"Zhangqiang\ {2104,\"Liminghong\ {3121,\"Wangxingda\ {4118,\"Liushaotao\ {1456,\"Wuminghong\ };

void sort(STU *ps,int size) {

int i,flag,pass;

/**/ /**/ for(pass=1;passflag=0;

for(i=0;i51

flag+=1;

temp=ps[i];ps[i]=ps[i+1];ps[i+1]=temp; }

if(/**/ /**/) break; } }

void main() {

int i,size=sizeof(mystudent)/sizeof(STU); clrscr();

printf(\"Students\\'information before sort:\\n\\n\");

printf(\"Number Name age Sex score\\n\\n\"); for(i=0;iprintf(\"%-7d%s%10d\%s%8d\\n\ (mystudent+i)->name,(mystudent+i)->age, (mystudent+i)->sex,(mystudent+i)->score); sort(mystudent,size);

printf(\"\\nStudents\\'information after sort:\\n\\n\");

printf(\"Number Name age Sex score\\n\\n\"); for(i=0;iprintf(\"%-7d%s%10d\%s%8d\\n\ (mystudent+i)->name,(mystudent+i)->age, (mystudent+i)->sex,(mystudent+i)->score); getch(); }

第9套

1.补充程序Ccon091.C,输入一个3行3列的整型数组,求其最大值和最小值。如输入:1 2 3 4 5 6 7 8 9 输出:max=9 min=1

-------Ccon091.C--------------------------------------------------------------------------- #include\"stdio.h\" #define ROW 3 #define COL 3 void main() {

int a[ROW][COL],i,j,max,min; clrscr();

printf(\"Please input the 9 integers:\\n\"); for(i=0;i52

/**/ /**/ for(i=0;iif(/**/ /**/) max=a[i][j]; if(a[i][j]/**/ /**/ }

printf(\"max=%d\\n\ printf(\"min=%d\\n\ getch(); }

2.补充程序Ccon092.C,计算s=1+12+123+1234+12345。

-------Ccon092.C--------------------------------------------------------------------------- #define N 5

#include void main() {

int t=0,/**/ /**/,i; for(i=1;i<=N;i++) {

t=/**/ /**/; s+=t; }

clrscr();

printf(\"\\ns=%d\\n\ getch(); }

3.补充程序Ccon093.C,输出Fibonacci数列的前15项。Fibonacci数列的计算方法是: fib(n)=1 (n=1,2)

fib(n)=fib(n-1)+fib(n-2) (n>=3)

-------Ccon093.C--------------------------------------------------------------------------- #include long fib(int n); void main() {

int k; clrscr();

printf(\"The first 15 data of Fibonacci is:\\n\\n\"); for(k=1;k<=15;k++) printf(\"%d\ printf(\"\\n\"); getch();

53

}

long fib(int n) {

if(n==1||n==2)

/**/ /**/ else

return /**/ /**/; }

第10套

1.补充程序Ccon0110.C,该程序的功能是计算三个学生的总成绩和平均成绩,其中三个学生的成绩存储在一个结构体数组中。

-------Ccon0110.C--------------------------------------------------------------------------- #include main() {

struct stu {

char name[10]; float score; };

/**/ /**/ stu[3]={\"Mary\ int i=0;

float total=0,aver=0; while(i<3) {

total=total+/**/ /**/; i++; }

aver=total/3;

printf(\"\\ntotal=%.2f,aver=%.2f\ getch(); }

2.补充程序Ccon0210.C,该程序的功能是找出数组中的最小数min1和次小数min2。 -------Ccon0210.C--------------------------------------------------------------------------- #include main() {

int i,a[10]={9,26,35,8,6,19,69,3,5,95}; int min1,min2; i=0;

min1=a[0]min2=a[0]>a[1]?/**/ /**/ for(i=2;i<10;i++) {

if(a[i]min2=min1; min1=a[i]; }

else if(a[i]/**/ /**/ }

printf(\"min1=%d,min2=%d\\n\ getch(); }

3.补充程序Ccon0310.C,使其实现用递归算法求平方根。求平方根的迭代公式如下: x112(xa0x) 0-------Ccon0310.C---------------------------------------------------------------------------

#include main() {

double x,y;

/**/ /**/ printf(\"Please input x;\\n\"); scanf(\"%lf\ y=mysqrt(x,1.0);

printf(\"The sqrt of %f=%f\\n\ getch(); }

double mysqrt(double a,double x0) {

double x1,y;

x1=/**/ /**/ if (fabs(x1-x0)>0.00001)

y=mysqrt(/**/ /**/); else

y=x1; return(y); }

第11套

1.补充程序Ccon0111.C,其功能是求20以内的所有素数,按每行显示4个素数输出。-------Ccon0111.C--------------------------------------------------------------------------- #include

#define /**/ /**/ main() {

55

int a,flag,i,j,m=0; for(i=2;i<=N;i++) {flag=1; j=2;

a=(int)sqrt((double)i); while(flag&&j<=a) { if(i%j==0)

/**/ /**/ j++; }

if(flag)

{printf(\"%3d\ /**/ /**/ if(m%4==0) printf(\"\\n\");

} }

getch(); }

2.补充程序Ccon0112.C,其功能是求下列级数的部分和。

x2x3xme1x

2!3!m!x例如:当m=100,x=2时,ex=7.3057

-------Ccon0112.C--------------------------------------------------------------------------- #include main() {

int i,m;

float x,s,tem;

printf(\"Input m and x\\n:\"); scanf(\"%d%f\ /**/ /**/

for(i=1;/**/ /**/;i++) {

tem*=x/i; s+=tem; }

printf(\"e**%.2f=%f\\n\ getch(); }

3. 补充程序Ccon0113.C,计算存放在数组score中12位学生成绩的平均分,并输出高于平均分的人数。

-------Ccon0113.C---------------------------------------------------------------------------

56

#include #define N 12 int count(int s[]) {

int i,c=0;

float sum=0,aver; for(i=0;iaver=/**/ /**/ for(i=0;iif(s[i]>=aver) c++; }

return(/**/ /**/); }

void main() {

int score[N]={67,78,66,79,73,82,69,85,77,80,93,72}; int cn;

cn=/**/ /**/(score); printf(\"Count is %d\\n\ getch(); }

第四部分:编程题(每小题8分,2小题/套)

说明如下:

(1) 在一对\"/**/\"之间编写程序,以完成题目的要求; (2) 不得删改程序中的\"/**/\"注释和其它代码;

(3) 源程序均在考生文件夹中,务必以原文件名保存程序;

(4) 按Alt+Tab键,切换考试程序与Turbo C;按Alt+Enter键,切换Turbo C

窗口大小。

第1套

1.打开Cprog011.C,完成其中的函数fun1,该函数的数学表达式是:

1sinxexfun1x

1x例如:fun1(0.76)= 2.175 fun1(3.00)= 5.307 fun1(3.76)= 9.111

57

--------Cprog011.C-------------------------------------------------------------------------------- #include #include double fun1(double x) {

/**/

/**/ }

void main() {

clrscr();

printf(\"fun1(0.76)=%8.3lf\\n\printf(\"fun1(3.00)=%8.3lf\\n\printf(\"fun1(3.76)=%8.3lf\\n\}

2.打开程序Cprog012.C,完成其中的函数fun2(int a[],int n,int b[],int c[]),实现:(1)将数组a中大于-20的元素,依次存放到数组b中; (2) 将数组b中的元素按照从小到大的顺序依次存放到数组c中; (3)函数返回数组b中的元素个数。

-----------Cprog012.C------------------------------------------------------------------------------ #include #include #include #include

int fun2(int a[], int n, int b[],int c[]) {

/**/

/**/ }

58

void main() {

int n = 10,i,nb;

int aa[10] = {12, -10, -31, -18, -15, 50, 17, 15, -20, 20}; int bb[10],cc[10]; clrscr( );

printf(\"There are %2d elements in aa.\\n \

printf(\"They are: \"); for(i=0; inb=fun2(aa,n,bb,cc);

printf(\"Elements in bb are:\"); for(i=0; iprintf(\"Elements in cc are:\"); for(i=0; iprintf(\"There are %2d elements in bb.\\n\}

59

第2套

1.打开Cprog021.C,完成其中的函数fun1,该函数的数学表达式是:

fun1xexx6x1.3

例如:fun1(0.76)= 3.582 fun1(3.00)= 5.369 fun1(3.76)= 8.931

--------Cprog021.C--------------------------------------------------------------------------------

#include #include double fun1(double x) {

/**/

/**/ }

void main() {

clrscr();

printf(\"fun1(0.76)=%8.3lf\\n\printf(\"fun1(3.00)=%8.3lf\\n\printf(\"fun1(3.76)=%8.3lf\\n\}

2. 打开程序Cprog022.C,完成其中的函数fun2(char a[],char b[],char c[]),实现:将三个字符串a、b、c从小到大排序后输出。 注意:字符串比较函数为strcmp(str1,str2),字符串赋值函数为strcpy(str1,str2)。 -----------Cprog022.C------------------------------------------------------------------------------ #include #include #include #include

60

void fun2(char a[],char b[],char c[]) {

/**/

/**/ }

void main() {

char str1[15]=\"Fuzhou\ clrscr();

fun2(str1,str2,str3);

printf(\"The ordered strings is:%s,%s,%s\\n\ getch(); }

61

第3套

1.打开Cprog031.C,完成其中的函数fun1,该函数的数学表达式是:

1.2,fun1x10,2x1,x3x3 x3例如:fun1(0.76)=1.200 fun1(3.00)=10.000 fun1(3.76)=8.520

--------Cprog031.C-------------------------------------------------------------------------------- #include #include double fun1(double x) {

/**/

/**/ }

void main() {

clrscr();

printf(\"fun1(0.76)=%8.3lf\\n\printf(\"fun1(3.00)=%8.3lf\\n\printf(\"fun1(3.76)=%8.3lf\\n\}

2.打开Cprog032.C,完成其中的函数fun (char *s),使程序实现统计输入字符串中空格的个数*/

-----------Cprog032.C----------------------------------------------------------------------------- #include int fun(char *s) { /**/

62

/**/ }

void main() {

char str[255]; gets(str);

printf(\"%d\\n\}

63

第4套

1.打开程序Cprog041.C,完成其中fun()函数,使其计算:

x00,fxx3.2

,x0sinx2 如 输入:12 输出f(12.000)=10.387 输入:32.25 输出f(32.250)=12.935 输入:0.113 输出f(0.113)=1568

---------Cprog041.C-------------------------------------------------------------------------------

#include #include double f(float x) {

/**/

/**/ }

void main() {

float x; double y;

printf(\"Please input a number:\\n\"); scanf(\"%f\y=f(x);

printf(\"f(%.3f)=%.3f\\n\getch(); }

2.打开程序Cprog042.C,完成其中的fun()函数,使程序打印出Fibonacci数列的前20个数。该数列(1,1,2,3,5,8,13,......)的第一、第二个数为1,从第三个数开始每个书等于前2个数字之和。

-----------Cprog042.C----------------------------------------------------------------------------- #include #include

double fun(int a[],int m) {

/**/

/**/

}

void main() {

int a[20],i; fun(a,20);

for(i=0;i<20;i++) printf(\"%d \printf(\"\\n\"); getch(); }

65

第5套

1.打开程序Cprog051.C,完成其中的f()函数,使其计算:

5.8x,x700; fxcosx2.1x700.1,如 输入:0.4 输出:f(0.40)=0.82

输入: 1.5 输出:f(1.50)=1.24 输入: 7.80 输出:f(780.00)=-1.00

-------------Cprog051.C-------------------------------------------------------------------------- #include #include double f(float x) {

/**/

/**/ }

void main() {

float x; double y;

printf(\"please input a number :\\n\"); scanf(\"%f\ y=f(x);

printf(\"f(%0.2f)=%0.2f\\n\ getchar(); }

2.打开程序Cprog052.C,完成其中的fun()函数使其判断一个矩阵是否为对称矩阵,若矩阵对称返回1,不对称返回0。说明:矩阵a是一个二维数组,若其中的第k行第j列的元素与第j行k第列的元素相同,则称其为对称矩阵,否则为非对称矩阵。

如 输入: 6 3 12 如 输入:6 9 12 3 18 8 3 18 8

12 8 7 34 8 22

输出:Yes 输出:No

-----------Cprog052.C------------------------------------------------------------------------------

66

#include #include int fun(int a[][3],int m) {

/**/

/**/ }

void main() {

int a[3][3],i,j; int b; fun(a,20);

for(i=0;i<3;i++) for(j=0;j<3;j++) scanf(\"%d\ b=fun(a,3); if(b==1) printf(\"Yes\\n\"); else printf(\"No\\n\"); getch(); }

67

第6套

1.打开程序Cprog061.C,完成其中的f()函数,使其计算:

x3,x300lgx2.6 fx1,x300 如 输入:0.8 输出:f(0.80)=0.96

输入: 4.5 输出;f(4.50)=107.05 输入;725 输出;f(725.00)=-1.00

----------Cprog061.C-------------------------------------------------------------------------------

#include #include double f(float x) {

/**/

/**/ }

void main() {

float x; double y;

printf(\"Please iuput a number:\\n\"); scanf(\"%f\ y=f(x);

printf(\"f(%0.2f)=%0.2f\\n\ getch(); }

2.打开程序Cprog062.C,完成其中的fun()函数,使其实现四则运算功能。 如 输入:3.2 2.1

输出:3.20+2.10=5.30 3.20-2.10=1.10 3.20*2.10=6.72 3.20/2.10=1.52

------------Cprog062.C------------------------------------------------------------------------

68

#include #include

float fun(float a,char flag,float b) {

/**/ /**/ }

void main() {

float a,b;

printf(\"Please input two numbers:\\n\"); scanf(\"%f%f\

printf(\"%.2f+%.2f=%.2f\\n\ printf(\"%.2f-%.2f=%.2f\\n\ printf(\"%.2f*%.2f==%.2f\\n\ printf(\"%.2f/%.2f==%.2f\\n\ getch( ); }

69

第7套

1.打开程序Cprog071.C,完成其中的f(x)的函数,使对其输入的一个月工资数额,求应交税款。设应交税款的计算公式如下:

x1600;0,x16005%,1600x2100; fx;x160010%25,2100x3100.x160015%125,x3100例如 输入:1825 输出:f(1825)=11.25

输入:2700 输出:f(2700)=85.00 输入:5655 输出:f(5655)=483.25

-----------Cprog071.C-----------------------------------------------------------------------------

#include #include double f(float x) {

/* */

/**/ }

void main() {

float x; double y; clrscr();

printf(\"Please input a number:\\n\"); scanf(\"%f\ y=f(x);

printf(\"f(%.2f)=%.2f\\n\ getch(); }

2.打开程序Cprog072.C,完成其中的fun函数,该函数将4阶矩阵A的各行中0之前的所有正数依次存放到数组b中,并返回这些正数之和。如矩阵A为

70

23410121314 21230243132330则调用函数fun()后,b[0]为1,b[1]为2,b[2]为23,b[3]为32,函数返回58。

--------------Cprog072.C---------------------------------------------------------------------------

#include #define ROW 4 #define COL 4

int fun(int a[][COL], int row, int b[]) {

/**/

/**/ }

void main() {

int sss=0, b[16] = {0};

int a[ROW][COL] = {{1,2,-3,-4}, {0,-12,-13,14}, {-21,23,0,24},{-31,32,-33,0}}; clrscr();

sss=fun(a, ROW, b);

printf(\"Sum of positive elements is %d\\n\ getch ( ); }

71

第8套

1.打开程序Cprog081.C,完成其中的f(x)函数,使其计算:

x2ex,f(x)x2ln2x,x0; x0.如 输入:-1.2 输出:f(-1.200)=0.241 输入:6 输出:f(6.000)=19.879

--------------Cprog081.C---------------------------------------------------------------------------

#include #include double f(float x) {

/**/

/**/ }

void main() {

float x; double y;

printf(\"Please input a number:\\n\"); scanf(\"%f\ y=f(x);

printf(\"f(%.3f)=%.3f\\n\ getch (); }

2.打开程序Cprog082.C,完成其中的f()函数,该函数将以指针数组的形式存放的n个字符串按照升序排序。(提示:字符串复制函数是 strcpy(cha*,char*,)),字符比较函数是strcmp(char*,char*)

----------Cprog082.C-------------------------------------------------------------------------------

#include #include void f(char **p,int n); void main()

72

{

int i;

char *p[5]={\"abc\ f(p,5); clrscr();

for(i=0;i<5;i++) printf(\"%s\\n\ getch(); }

void f(char **p,int n) {

/**/

/**/ }

73

第9套

1.打开程序CPROG091.C,完成其中的f()函数,使其返回方程ax2bxc0的两个根中较大的根,求根公式为

x1,2bb24ac,其中假设:a0且b24ac0 2a-------------CPROG091.C-------------------------------------------------------------------------

#include #include

double f(float a,float b,float c) {

/**/

/**/ }

void main() {

float x;

printf(\"The bigger root is %.2f\\n\getch( ); }

2.打开程序Cprog092.C,完成其中的strcmp1()函数,该函数实现判别两字符串str1和str2的大小。

----------CPROG092.C----------------------------------------------------------------------------

#include

int strcmp1(const char *str1,const char *str2) {

/**/

/**/

74

}

void main() {

int com; char *ps1=\"uvwx\ clrscr( );

com=strcmp1(ps1,ps2); if( com>0 ) printf(\"%s>%s\ if( com==0 ) printf(\"%s=%s\ if( com<0 ) printf(\"%s<%s\

getch( ); }

75

第10套

1.打开程序Cprog101.C,完成其中的fun(x)函数,该函数的功能是:根据输入

2n1xn的x和n的值,计算funx1.0x2.0,0n10,将计算结果存

nn1入数组元素a[0]中,并将计算结果的小数部分存入a[1]中。

-----------Cprog101.C------------------------------------------------------------------------------

#include #include

void fun(double a[], double x, int n) {

/**/

/**/ }

void main() {

int n;

double a[2], x;

printf(\"\\nPlease enter x,n: \"); scanf(\"%lf,%d\

while(x<1.0||x>2.0||n<0||n>10) { printf(\"\\nInvialid data(1.0<=x<=2.0,0fun(a,x,n);

printf(\"\\nResult:a[0]=%f,a[1]=%f\getch( ); }

2.打开程序Cprog102.C,完成其中的fun(x)函数,该函数的功能是:将已按升序排列好的数组a和已按降序排列好的数组b中的所有元素按降序存入数组c中。 -----------Cprog102.C------------------------------------------------------------------------------ #define N 6

76

#define M 9

void fun(int a[], int b[], int c[]) {

/**/

/**/ }

void main() {

int a[N]={2, 5, 8, 10,18,24}, b[M]={96,88,70,36,24,18,11,10,2}; int c[N+M],n; fun(a,b,c);

printf(\"The result is\"); for(n=0;n77

第11套

1.打开考生文件夹中的Cprog111.c,完成其中的函数fun,该表达式是:

1,n0Pnxx,n1

2n1xPxn1Px,n1n1n2n例如:当x5.2,n6时,函数的值为4.724444。

该函数返回数组a中的次大数(即仅次于最大数的数)。

------------------------Cprog111.c------------------------------------------------------------------

#include void main() {

double x; int n;

double fun (double x, int n); printf (\"Please enter x,n:\"); scanf (\"%lf%d\ printf (\"fun=%lf\\n\ getch(); }

double fun (double x, int n) {

/**/

/**/ }

2.打开考生文件夹中的Cprog112.c,完成其中的search(int a[])函数,该函数返回数组a中的次大数(即仅次于最大数的数)。

--------------Cprog112.c---------------------------------------------------------------------------

#include #define N 8

78

int search (int a[]) {

/**/

/**/ }

void main() {

int a[N]={16,8,66,45,6,79,40,58}; int max_next;

max_next=search(a);

printf (\"Max_next is %d\\n\ getch(); }

79

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务