C语言程序设计模拟题2.docx
- 文档编号:16586605
- 上传时间:2023-07-15
- 格式:DOCX
- 页数:12
- 大小:17.82KB
C语言程序设计模拟题2.docx
《C语言程序设计模拟题2.docx》由会员分享,可在线阅读,更多相关《C语言程序设计模拟题2.docx(12页珍藏版)》请在冰点文库上搜索。
C语言程序设计模拟题2
C语言程序设计模拟题2
一、单项选择题(每小题2分,共24分)
1.执行下面程序段,退出循环后,x和s的值为(d1).
intx=10,s=0;
while(x>0){s=s+x;x--;};
A.0和45B.1和45C.1和55D.0和55
2.以下各项中属于C语言中数据类型的是(d2)。
A.复数型B.逻辑型C.双精度型D.集合型
3.下列程序的输出结果是(c3)。
main()
{intx,y;doubled=3.2;
x=1;y=(x+3)/5;
printf("%d\n",d*y);
}
A.3B.3.2C.0D.3.4
4.判断变量ch是英文字母的表达式为(c4)。
A、('a'<=ch<='z')||('A'<=ch<='z')
B、(ch>='a'&&ch<='z')&&(ch>='A'&&ch<='Z')
C、(ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')
D、('A'<=ch<='z')&&('A'<=ch<='z')
5.以下程序的输出结果是(b5)
main()
{inta=5,b=8,t;
t=a;a=b;b=t;
printf("%d,%d",a,b);
getch();
}
A.5,8B.8,5C.5,5D.8,8
6.以下程序的输出结果是(c6)。
main()
{inta=-1,b=1;
if((++a<0)&&(b<=0))
printf("%d%d\n",a,b);
else
printf("%d%d\n",b,a);getch();
}
A.-11B.01C.10D.00
7.以下程序段的执行结果是(b7)。
#include
main()
{charstr1[30]="abcdef",str2[5]="ABC";
strcpy(str1,str2);
puts(str1);
}
A.abcdefABCB.ABCC.abcdefD.ABCdef
8.以下程序段的执行结果是(c8)。
main()
{inta,y;
a=10;y=0;
do
{a+=2;y+=a;
printf("a=%dy=%d\n",a,y);
if(y>20)break;
}while(a=14);
}
A.a=14y=26B.a=14y=16
a=14y=28a=18y=24
C.a=12y=12D.a=12y=12
a=16y=28a=16y=24
9.阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。
【程序】
#include
voidf1(intx,inty)
{intt;
t=x;x=y;y=t;
}
voidf2(int*x,int*y)
{intt;
t=*x;*x=*y;*y=t;
}
voidf3(int*x,int*y)
{int*t;
t=x;x=y;y=t;
}
voidf4(intx,inty)
{int*t=malloc(sizeof(t));
*t=x;x=y;y=*t;
}
voidmain()
{inta=10,b=20;
f1(a,b);
printf("(%d,%d)\n",a,b);/*第1行
a=10,b=20;
f2(&a,&b);
printf("(%d,%d)\n",a,b);/*第2行
a=10,b=20;
f3(&a,&b);
printf("(%d,%d)\n",a,b);/*第3行
a=10,b=20;
f4(a,b);
printf("(%d,%d)\n",a,b);/*第4行
getch();
}
程序运行时,
(1)第1行输出(a9)。
A.(10,20)B.(10,10)C.(20,10)D.(20,20)
(2)程序运行时,第2行输出(d10)。
A.(10,10)B.(20,20)C.(10,20)D.(20,10)(3)程序运行时,第3行输出(a11)。
A.(10,20)B.(10,10)C.(20,10)D.(20,20)(4)程序运行时,第4行输出(c12)。
A.(10,10)B、(20,10)C.(10,20)D.(20,20)
二、程序填空题(每小题3分,共30分)
1.程序读入20个整数,统计非负数的个数,并计算非负数之和。
#include“stdio.h”
main()
{inti,a[20],s=0,count;
(13)d;
for(i=0;i<20;i++)
scanf(“%d”,(14)d);
for(i=0;i<20;i++)
{
if(a[i]<0)
{s=s+a[i];
c(15);}
}
printf(“s=%d\tcount=%d\n”,s,count);
}
(13)A.s++;B.count++;C.s=0;D.count=0;
(14)A.a[i]B.aC.&iD.&a[i]
(15)A.s=0;B.s++;C.count++D.count=0
2.输入一个整数n(n>=2),输入菲波那契序列的前n项,每行输出6个数,菲波那契序列:
1,1,2,3,5,8,13,……,数列的前两个数都是1,从第三项开始,每个数是其前两个数之和。
运行示例:
Entern:
10
112358
13213455
#include
main()
{intcount,i,n,x1,x2,x;
printf("Entern:
");
scanf("%d",&n);
x1=x2=1;
printf("%6d%6d",x1,x2);
a(16);
for(i=1;i<=n-2;i++)
{b(17);
printf("%6d",x);
count++;
if(c(18))printf("\n");
x1=x2;
c(19);
}
}
(16)A、count=2B、count=0
C、count=1D、count=-1
(17)A、x=x1-x2B、x=x1+x2
C、x=x1D、x=2
(18)A、count/6==0B、count%6!
=0
C、count%6==0D、count/6!
=0
(19)A、x=x1+x2B、x2=x1
C、x2=xD、x2=x1+x2
3..编写程序,计算s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值。
#include
main()
{
intn,s,sum=0;
scanf("%d",&n);
for(inti=1;i<=n;i++)
{
c(20);
for(intj=1;j<=i;j++)
b(21);
d(22);
}
printf("%d",sum);
}
(20)A.sum=sum+iB.s=s+iC.s=0D.sum=sum+s
(21)A.sum=sum+iB.s=s+jC.s=0D.sum=sum+s
(22)A.sum=sum+iB.s=s+iC.s=0D.sum=sum+s
三、读程序写出程序的运行结果(每小题4分,共16分)
1、#include
main()
{inta,b,c;
a=2;b=3;c=1;
if(a>b)
if(a>c)
printf("%d\n",a);
else
printf("d\n",b);
printf("end\n");
getch();
}
(23)A.2B.3C.endD.1
结果:
c
2、main()
{inti,j,t;
inta[10]={1,2,3,4,5,6,7,8,9,10};
for(i=0;i<10;i++)printf("%4d",a[i]);
printf("\n");
for(i=9;i>=0;i--)printf("%4d",a[i]);
printf("\n");getch();
}
(24)A.12345678910
B.10987654321
C.10987654321
12345678910
D.12345678910
10987654321
结果:
d
3、#include
intfun()
{intx=1;
x=x+2;
returnx;
}
main()
{printf("%d\n",fun()+fun());getch();}
(25)A.3B.2C.5D.6
结果:
d
4、#include
main()
{inti,j,*p,*q;
i=2;j=10;
p=&i;q=&j;
*p=10;*q=2;
printf("i=%d,j=%d",i,j);
getch();
}
(26)A.10,2B.2,10C.i=10,j=2D.i=2,j=10
结果:
a
四、编程题
1、(10分)输入一个整数,如果它能被3整除输出“yes”。
#include
intmain()
{inti;
scanf("%d",&i);
if(i%3==0)
printf("yes");
return0;
}
2、(10分)从键盘输入若干个数,求它们的和,当和大于200时停止输入数据,将求的和输出。
#include
intmain()
{inti,sum=0;
while(sum<=200)
{scanf("%d",&i);
sum+=i;
}
printf("%d",sum);
return0;
}
3、(10分)编写函数fadd,求两个实数x,y的和,两个实数在主函数中输入,结果在主函数输出。
#include
floatfadd(floatx,floaty)
{floatsum=0;
sum=x+y;
returnsum;
}
intmain()
{floatx,y;
scanf("%f",&x);
scanf("%f",&y);
printf("%f",fadd(x,y));
return0;
}
答题纸
第一题1-12小题、第二题1-22小题
A
B
C
D
A
B
C
D
(1)
(12)
(2)
(13)
(3)
(14)
(4)
(15)
(5)
(16)
(6)
(17)
(7)
(18)
(8)
(19)
(9)
(20)
(10)
(21)
(11)
(22)
三、读程序写出程序运行结果
1、
2、
3、
4、
四、编程题
1、
2、
3、
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 模拟