- 2
- 0
- 约1.6千字
- 约 4页
- 2016-12-09 发布于重庆
- 举报
C语言期末考试复习题5.
一、单选题( 20分)。
二、填空题( 24分)。
给定程序的功能是:从键盘上输入一年份数,判断某其是否为闰年。闰年的条件是:能被4整除,但不能被100整除的年份或能被100整除,又能被400整除的年份。
将适当的关键字或符号填入“__数值__”位置,并将“__数值__”删除,使程序得到正确结果。不许增减程序行,且不得修改其它部分。
#includestdio.h
#includemath.h
#includestring.h
main()
{
int year,leap;
/**************found*****************/
__1__
/**************found****************/
if((year%4==0 __2__)||(year%400==0))
leap=1;
else
leap=0;
/**************found****************/
if( __3__ )
printf(%d is ,year);
else
printf(%d is not ,year);
printf(a leap year.\n);
}
三、改错题( 21分)。
给定程序的功能是:输入一个字符判断是否是大写字母,如果是将它转换成小写字母;如果不是,不转换。然后输出最后得到的字符。
请改正/****found****/下一行语句中的错误,并调试出正确结果。不得增加或删减程序行,且不得修改其它行。
#includestdio.h
#includemath.h
#includestring.h
main()
{
char ch;
/************found****************/
printf(%c,ch);
if(ch=Ach=Z)
/*************found***************/
{ ch-=32;
printf(%c,ch);
}
/*************found***************/
break;
printf(%c,ch);
}
四、编程题( 35分)。
给定程序的功能是:已给定一行字符,要求统计出其中大写字母的个数。
不允许改动预编译命令行及主程序,且必须运行程序。
答案:
一、
1、2 2、2 3、1 4、2 5、1 6、3 7、4 8、2 9、4 10、3
二、
1、scanf(%d,year);
2、if((year%4==0year%100!=0)||(year%400==0))
if((year%4==0year%100)||(year%400==0))
3、if(leap)
if(leap==1)
三、
1、scanf(%c,ch);
scanf(%d,ch);
2、{ch+=32;
{ch=ch+32;
{ch=32+ch;
{ch=ch+a-A;
3、else
四、编程题参考程序
int count=0;
while(*p!=\0)
{if(*p=A*p=Z)
count++;
p++;}
return count;
原创力文档

文档评论(0)