模拟试卷(八)
一、单项选择题(在本题的每一小题的备选答案中只有一个答案是正确的,请把你认为正确的答案的题号,填入题干的括号内。多选不给分。每题1分,共20分)
1.语句
printf("%d\n",(a=2)&&(b=-2));
则输出结果是( )。
(1)无输出 (2)结果不确定 (3)-1 (4)1
2.设有如下的变量定义
int i=8,k,a,b;
unsigned long w=5;
double x=1.42,y=5.2;
则以下符合c语言语法的表达式是( )。
(1)a+=a-=(b=4)*(a=3) (2)x%(-3)
(3)a=a*3=2 (4)y=float(i);
3.语句
printf("a\bre\'hi\'y'\\\bou\n");
的输出结果是( )。(说明:'\b'是退格符)
(1)a\bre\'hi\'y\\\bou (2)a\bre\'hi\'y\bou
(3)re'hi'you (4)abre'hi'y\bou
4.执行以下程序的输出结果是( )。
#include <stdio.h>
main()
{
int i;
for (i=1;i<6;i++)
{
if (i%2)
{
printf("#");
continue;
}
printf("*");
}
printf("\n");
}
(1)#*#*# (2)##### (3)***** (4)*#*#*
5.在执行以下程序时,为了使输出结果为t=4,则给a和b输入的值应满足的条件是( )。
#include <stdio.h>
main()
{
int s,t,a,b;
scanf("%d,d",&a,&b);
s=1;t=1;
if (a>0)
s=s+1;
if (a>b)
t=s+t;
else if (a==b)
t=5;
else
t=2*s;
printf("t=%d\n",t);
}
(1)a>b (2)a<b<0 (3)0<a<b (4)0>a>b
6.若执行下述程序时从键盘输入
3 4![]()
则输出结果是( )。
#include <stdio.h>
main()
{
int a,b,s;
scanf("%d%d",&a,&b);
s=a;
if (a<b)
s=b;
s*=s;
printf("%d\n",s*s);
}
(1)186 (2)256 (3)324 (4)400
7.执行下述程序的输出结果为( )。
#include <stdio.h>
main()
{
int n=0;
int sum=0;
while (n++,n<50)
{
if (n==(n/2)*2)
continue;
sum+=n;
}
printf("%d\n",sum);
}
(1)50 (2)625 (3)1275 (4)49
8.下述描述中不正确的是( )。
(1)字符型数组中可以存放字符串
(2)可以对字符型数组进行整体输入、输出
(3)可以对整型数组进行整体进行输入、输出
(4)不能在赋值语句中通过赋值运算符“=”对字符型数组进行整体赋值
9.给出以下定义
char x[]="abcdefg";
char y[]={'a','b','c','d','e','f','g'};
则正确的叙述为( )。
(1)数组x和数组y等价 (2)数组x和数组y的长度相同
(3)数组x的长度大于数组y的长度 (4)数组x的长度小于数组y的长度
10.设有如下变量说明语句
int i;
char *s="a\045+045\'b";
则执行下述for语句后,变量i的结果值是( )。
for (i=0;*s++;i++);
(1)7 (2)8 (3)9 (4)以上三个答案都是错误的
11.执行下述程序的输出结果是( )。
#include <stdio.h>
main()
{
char *s="121";
int k=0,a=0,b=0;
do
{
k++;
if (k%2==0)
{
a=a+s[k]-'0';
continue;
}
b=b+s[k]-'0';
a=a+s[k]-'0';
}while (s[k+1]);
printf("%k=%d a=%d b=%d\n",k,a,b);
}
(1)k=3 a=2 b=3 (2)k=3 a=3 b=2
(3)k=2 a=3 b=2 (4)k=2 a=2 b=3
12.执行以下程序的输出结果是( )。
#include <stdio.h>
#include <string.h>
main()
{
char *p1,*p2,str[50]="xyz";
p1="abcd";
p2="ABCD";
strcpy(str+2,strcat(p1+2,p2+1));
printf("%s",str);
}
(1)xyabcAB (2)abcABz (3)ABabcz (4)xycdBCD
13.执行下述程序的输出结果是( )。
#include <stdio.h>
void func(int a,int b,int c)
{
a=456;
b=567;
c=678:
}
main()
{
int x=10,y=20,z=30;
func(x,y,z);
printf("%d,%d,%d\n",z,y,x);
}
(1)30,20,10 (2)10,20,30 (3)456,567,678 (4)678,567,456
14.下述程序执行后的输出结果是( )。
#include <stdio.h>
void func(int *a,int b[])
{
b[0]=*a+6;
}
main()
{
int a,b[5];
a=0;
b[0]=3;
func(&a,b);
printf("%d\n",b[0]);
}
(1)6 (2)7 (3)8 (4)9
15.执行下述程序的输出结果是( )。
#include <stdio.h>
int x=1;
int f1()
{
return (++x);
}
int f2(int x)
{
x=3;
return (++x);
}
int f3(int x)
{
return (++x);
}
main()
{
int x=10;
printf("%d\n",f1());
printf("%d\n",f2(x));
printf("%d\n",f3(x));
}
(1)2 (2)2 (3)10 (4)10
4 2 4 11
11 2 11 11
16.执行以下程序的输出结果是( )。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void space (char *str)
{
int i,t;
char ts[81];
for (i=0,t=0;str[i]='\0';i+=2)
if (!isspace(*(str+i))&&(*(str+1)!='a'))
ts[t++]=toupper(str[i]);
ts[t]='\0';
strcpy(str,ts);
}
main()
{
char s[81]={"a b c d ef g"};
space(s);
puts(s);
}
(1)abcdeg (2)bcde (3)ABCDEF (4)BCDE
17.根据下面结构体类型和结构体数组的定义,能打印字母'M'的语句是( )。
struct peron
{
char name[9];
int age;
};
struct person class[10]={
"John",17,
"Paul",19,
"Mary",18,
"Adam",16
};
(1)printf("%c\n",class[3].name);
(2)printf("%c\n",class[3].name[1]);
(3)printf("%c\n",class[2].name[1]);
(4)printf("%c\n",class[2].name[0]);
18.设有以下定义和说明
#include <stdio.h>
#define STD struct std
STD
{
char num[6];
char name[8];
float mark[4];
} a[30];
FILE *fp;
今文件中以二进制形式存有一批学生数据,且该文件已正确地打开,文件指针定位于文件开关。若要从文件中读取30个学生的数据放入数组a中,以下实现此功能的语句中错误的是( )。
(1)for (i=0;i<30;i++)
fread(&a[i],sizeof(STD),1L,fp);
(2)for (i=0;i<30;i++)
fread(a+i,sizeof(STD),1L,fp);
(3)fread(a,sizeof(STD),30L,fp0;
(4)for (i=0;i<30;i++)
fread(a[i],sizeof(STD),1L,fp);
19.执行下述程序所完成的功能是( )。
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *in,*out;
char ch,infile[10],outfile[10];
printf("Enter the infile name:\n");
scanf("%s",infile);
ptintf("Enter the outfile name:\n");
scanf("%s",outfile);
if ((in=fopen(infile,"r"))==NULL)
{
printf("Cannot open infile.\n");
exit(0);
}
if ((out=fopen(outfile,"w"))==NULL)
{
printf("Cannot open outfile.\n");
exit(0);
}
ch=fgetc(in);
while (!feof(in))
{
fputc(ch,out);
ch=fgetc(in);
}
fclose(in);
fclose(out);
}
(1)将磁盘文件的信息在屏幕上显示的功能
(2)将两个磁盘文件合二为一的功能
(3)将一个磁盘文件复制到另一个磁盘文件中
(4)将两个磁盘文件合并并且在屏幕上输出
20.系统对预处理命令(如宏替换、文件包含、条件编译)的处理时机是( )。
(1)编译源程序 (2)编译源程序之前 (3)连接目标文件时 (4)运行程序时
二、填充题(每空2分,共30分)
1.下述算术表达式的结果值是_____________。
(4+5)*3*(5/2)
2.设字符变量ch具有英文大写字母的字符值。问运用位运算,能表示其相应英文小写字母的表达式是____________。(比如,设ch的字符值为'A',则该运用位运算的表达式的字符值应为'a')。
3.设有以下变量说明语句
char w='A';
int x=10;
float y=20;
double z=30;
则执行赋值语句
x=w*x+z-y;
之后x所得值的数据类是_____________。
4.执行下述程序的输出结果是_______________。
#include <stdio.h>
main()
{
long a=0xfffffL;
int b=0;
b=a;
printf("%d\n",b);
}
5.当运行下述程序时,其输出结果是____________。
#include <stdio.h>
main()
{
int y=18,i=0,j,a[8];
do
{
a[i]=y%2;
i++;
y=y/2;
} while (y>=1);
for (j=i-1;j>=0;j--)
printf("%d",a[j]);
printf("\n");
}
6.执行下述程序的输出结果是____________。
#include <stdio.h>
main()
{
int i,j,sum,m,n=4;
sum=0;
for (i=1;i<=n;i++)
{
m=1;
for (j=1;j<=i;j++)
m=m*j;
sum=sum+m;
}
printf("xum=%\n",sum);
}
7.下述程序的功能是读取20个整数,统计其中非负整数的和以及个数并输出之。请填空。
#include <stdio.h>
main()
{
int i,a[20],s,count;
s=count=0;
for (i=0;i<20;i++)
scanf("%d",&a[i]);
for (i=0;i<20;i++)
{
if (a[i]<0)
___________;
s+=a[i];
count++;
}
printf("s=%d,count=%d\n",s,count);
}
8.执行下述程序可实现:从键盘上输入一行字符(以回车键结尾),作为字符串存入一个字符数组中,然后输出该字符串。请填空。
#include <stdio.h>
main()
{
char s[81],*ps;
int i;
for (i=0;i<80;i++)
{
s[i]=getchar();
if (s[i]=='\n')
break;
}
s[i]='\0';
ps=s;
while (*ps)
putchar (___________);
putchar('\n');
}
9.执行下述程序
#include <stdio.h>
main()
{
char s1[]="I like Turbo C!",s2[20];
char *ps1=s1,*ps2=s2;
scanf("%s",ps2);
printf("%s\n",ps2);
printf("%s\n",ps1);
}
时,若从键盘输入
I like C++ and Jave!![]()
则输出结果是___________________。(两行)
10.执行下述程序的输出结果是______________。
#include <stdio.h>
main()
{
char *p="abcdefghijk";
while (*p++!='e');
printf("%c\n",*p0;
}
11.执行下述程序的输出结果是___________。
#include <stdio.h>
main()
{
char *p[]={"BOOL","OPK","H","SP"};
int i;
for (i=3;i>=0;i--,i--)
printf("%c",*p[i]);
printf("\n");
}
12.下面的程序是求数组中的最小元素,输出最小元素的下标及最小元素值。请填空。
#include <stdio.h>
void findmin(int *s,int n,int *k)
/*s是指向数组首地址的指针,n是数组大小,k是指向数组中最小数组元素的指针*/
{
int p;
for (p=0,*k=p;p<n;p++)
if (s[p]<s[*k})
______________;
}
main()
{
int a[10],i,*k=&i;
for (i=0;i<10;i++)
scanf("%d",&a[i]);
findmin(a,10,k);
printf("%d,%d\n",*k,a[*k]);
}
13.下述程序中函数calc的功能是对传送过来的两个实数求出和值与差值,并通过两个指针形参分别将这两个值传送回调用函数。请填空。
#include <stdio.h>
void calc(float x,float y,float *add,float *sub)
{
________________________;
}
main()
{
float x,y,add,sub;
printf("Enter x,y:");
scanf("%f%f",&x,&y);
calc(x,y,&add,&sub);
printf("x+y=%f,x-y=%f\n",add,sub);
}
14.执行下述程序的输出结果是_____________。
#include <stdio.h>
void printd(int n)
{
int i;
if (n<0)
{
putchar('-');
n=-n;
}
putchar (n%10+'0');
if ((i=n/10)!=0)
printd(i);
}
main()
{
int m;
m=-654;
printd(m);
printf("\n");
}
15.设有如下结构体类型定义
struct node
{
int data;
strut node *link;
};
并设已生成如下之单向循环链表

下面整型函数min3的功能是:计算由结构体指针变量first所指向的单向循环链表中每3个相邻结点数据域值之和,返回其中最小的和值。请填空。
int min3(struct node *first)
{
struct node *p=first;
int m,m3;
m3=p->data+p->link->data+p->link->link->data;
for (p=p->link->;p!=first;p=p->link)
{
m=p->data+p->lind->data+p->lind->link->data;
if (_____________)
m3=m;
}
return (m3);
}
三、程序分析题(每题5分,共30分)
1.阅读程序,写出执行该程序的输出结果。
#include <stdio.h>
main()
{
int a=11,b=10;
a*=b;
printf("%d\n",a);
a/=b+1;
printf("%d\n",a);
a^=b;
printf("%d\n",a);
b&=a;
printf("%d\n",b);
a=a==b;
printf("%d\n",a);
}
2.阅读程序,写出执行该程序的输出结果。
#include <stdio.h>
main()
{
int n,k,i,s;
for (n=8;n<=12;n++)
{
s=0;
k=1;
for (i=1;i<=n;i++)
{
s+=i*k;
k*=-1;
}
printf("%d\n",s);
}
}
3.阅读程序,写出执行该程序的输出结果。
#include <stdio.h>
#define N 5
main()
{
int i,j,k;
int a[N+1],b[N+1][N+1];
for 9k=1;k<=N;i++)
a[k]=k;
for (i=1;j<=N;i++)
for (j=a;j<=i-1;j++)
b[i][j]=b[i-j][N];
for (i=a;i<]N;i++)
{
for (j=1;j<=N;j++)
printf("%4d",b[i][j]);
printf("\n");
}
}
4.阅读程序,写出执行该程序的输出结果。
#include <stdio.h>
#define N 4
main()
{
int i;
char c;
printf("%c\n",'a');
for (i=1;i<=N;i++)
{
c='a'+i;
printf("%c",c);
func(i,c);
}
}
func(int k,char cc)
{
int i;
for (i=1;i<=k-1;i+=)
printf(" ");
printf("%c\n",cc);
}
5.阅读程序
#include <stdio.h>
#define MAX 20
int fib(int n)
{
int res;
if (n==0)
res=0;
else if (n==1)
res=1;
else
res=fib(n-1)+fib(n-2);
return (res);
}
main()
{
int m,n;
printf("Input n(0<=n<=%d): "MAX);
scanf("%d",&n);
for (m=0;m<=n;m++)
{
printf("%6d",fib(m));
if ((m+1)%5==0)
printf("\n");
}
printf("\n");
}
当运行程序时,若有下述交互信息(带下划线的为输入信息)
Input n(0<=n<=20):![]()
请写出接下去的输出结果。
6.阅读程序
#include <stdio.h>
#include <stdlib.h>
#define LINK struct link
#define SIZE sizeof(LINK)
LINK
{
int vals;
LINK *poit;
};
LINK *lheak;
1stbuilt()
{
LINK *head,*next;
head=(LINK *)malloc(SIZE);
1head=head;
next=head;
scanf("%d",&next->vals);
while (next->vals!=-1)
{
next->poit=(LINK *)malloc(SIZE);
next=next->poit;
scanf("%d",&next->vals);
}
next->poit=NULL;
}
1stwrite(LINK *head)
{
LINK *next;
next=head;
while (next!=NULL)
{
if (next->vals%2==0)
printf("%4d",next->vals);
next=next->poit;
}
print("\n");
}
main()
{
1stbuilt();
1stwrite(1head);
}
当程序运行时,若从键盘输入
2 5 8 6 3 4 -1 4![]()
请画出调用1stbuilt()后所生成的单链表结构图并写出程序的输出结果。
四、程序设计题(每题10分,共20分)
1.两正整数a、b,若a的所有包含1但不包含自身的因子和等于b,b的所有包含1但不包含自身的因子和又等于a,则称a、b为一对亲密数或一亲密数对。例如,设a=b、b=6,则
a=6=1+2+3=b
b=6=1+2+3=a
故6与6是一亲密数对。编写程序,求1000以内的亲密对,并显示结果。请填空完善程序。
#include <stdio.h>
#define MAXNUM 1000
int factorsum(int n)
{
int index,sum;
sum=1; /*1是因子*/
for (index=2;index<=______________;index++)
if (________(2)__________)
sum+=index; /*index亦是因子*/
return(sum);
}
main()
{
int thisa,thisb,thata;
printf("The pairs of amicable number between 1 and %d are:\n",MAXNUM);
for (thisa=2;thisa<=_______(3)_______;thisa++)
{
thisb=factorsum(thisa);
thata=_________(4)_______;
if (__________(5)_______)
printf("%6d%6d\n",thisa,thisb);
} /*for thisa */
}
2.编写程序,生成一个新文本文件,它由一个已知文本文件的所有奇数行组成。要求书籍文本文件名和新文本文件名均从键盘输入。请填空完善程序。
#include <stdio.h>
main()
{
FILE *fold,*fnew;
char ch,fname[20];
int i;
do
{
printf("Enter name of existed text file to be read:");
scanf("%s",fname);
if ((fold=fopen(fname,"r"))==NULL)
printf("File %s can't open!\n",fname);
} while (fold==NULL);
do
{
printf("Enter mane of new text file to be written:");
scanf("%s",fname);
if ((__________(1)________==NULL)
printf("File %s can't open!\n",fname);
} while (________(2)________);
i=1;
while (!feof(fold))
{
while ((ch=fgetc(fold))!=______(3)______)
{
if (i%2==________(4)_______)
fputc(ch,fnew);
}
fputc('\n',fnew);
__________(5)_________;
}
fclose(fold);
fclose(fnew);
}
模拟试题(八)参考解答
一、单项选择题(每题1分,共20分)
1.(4) 2.(1) 3.(3) 4.(1) 5.(3) 6.(2) 7.(2) 8.(3) 9.(3) 10.(2)
11.(3) 12.(4) 13.(1) 14.(1) 15.(1) 16.(4) 17.(4) 18.(4) 19.(3) 20.(2)
二、填充题(每空2分,共30分)
1.54
2.ch|32 (或ch|0x20或ch|040或ch|'a'-'A'等)
3.int型(或整型) 4.-1
5.10010 6.sum=33
7.continue 8.*ps++
9.I
I like Turbo C!
10.f 11.so
12.*k=p; 13.*add=x+y,*sub=x-y
14.-456 15.m<m3 (或m<=m3)
三、程序分析题(每题5分,共30分)
1.110
10
0
0
1
2.-4
5
-5
6
-6
3. 1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
3 4 5 1 2
2 3 4 5 1
4.a
bb
cc
d d
e e
5. 0 1 1 2 3
5 8 13 21 34
55 89 144 233 377
610
6.调用1stbuilt()后所生成的单链表结构图为

而程序的输出结果是
2 8 6 4
四、程序设计题(每题10分,共20分)
1.(1)n/2
(2)n%index==0
(3)MAXNUM (或1000)
(4)factorsum(thisb)
(5)thata==thisa (或thisa==thata)
2.(1)fnew=fopen(fname,"w")
(2)fnew==NULL
(3)'\n'
(4)1
(5)i=i+1 (或i++)