大一c语言期末试及题参考答案
2004级信息学院《?C语言设计》考试试题?
一、判断下列语句或?程序的对错。 1?0分 √
1 i?nt x=y=z=’?0’; ? (×) y,z没?有定义
2 #inc?lude ; ? (×) 不能有分?号,#开头的结尾均不?能有分号;
3 pr?intf(“%s\n?”,”c langu?age”); ? (√)
4 fl?oat a[100?];
int *p=?a; ? ? ?(×) 数据类?型不匹配
5 cha?r str[20];?
6 int dat?a[4]={0,1,?2,3,4}; ? (×)五?个元素,但是只有四个?单元
7 float? x=1.45e+3?10L; (×?)数值越界
8 in?t xyz-1=2;? ? ? (×?)
9 int x=?‘\xae’ ; ? ? ? (√)
?10 int *p,?a[2][3] ;
?p=a ; ? ? ? (×?) 数据类型不匹?配
二 计算下?列表达式的值 ? 10分
设 ?unsigned i?nt a=10,b=?17,c=5,d=3?;
float f ?;
(1)f=?b/c ? ? ? ? ( 3.0 )?
(2)!(a?+b)+c-1&&b?+c/2 ? ? ? ( 1 )
? (3)(a^b)+?(c>>1+d) ? ? ? ( ? 0x1b )
? (4)a+=b%=?a=b ? ? ? ( ? 17 )
?(5)a=2,b=a?*++b ? ? ? ( ?2 )
三 程序改错? ? ? ?10分
求两个浮点数?的平方和及平方差
#?include
fl?oat calcul?ate (float? x,float y?,float *su?b);添加函数原型声?明
main ()?
{
float a?,b;
float ? add_reasu?lt, sub_r?esult;
sca?nf (“%f,%f?”,a,b);
ad?d_result=c?alculate(a?,b,&sub_re?sult);
pri?ntf( “a*a+?b*b=%d,a*a?-b*b=%d\n”?,add_resul?t,sub_resu?lt);
}
fl?oat calcul?ate (float? x,float y?,float *su?b) 添加函数?类型
{
float? *temp; ? ? 应该直接定义为?变量float te?mp;
sub=a*?a-b*b ; ? ? *sub=a*a?-b*b;
temp? = a*a+b*b?;
return *?temp; ? return? temp
}
统计?N 个字符中大写字母?和数字字符的个数
?#include <?stdio.h>
?#define N ? 5
Count(?char *str,?int *resul?t); 添加函数声?明
main (?)
{
ch?ar string[?N][80];
? char i;
? int Cap?ital_Count?=0,Num_Cou?nt=0;需要初始化?为0
fo?r(i=0;i
scanf?( “%s”,&st?ring[i]) ;? 去掉&符
?for(I=0;I<?N ;I++)
Cap?ital_Count?+=Count(st?ring[I],&N?um_Count);?
Printf?(“Capital ?count :=%d?,numbercou?nt=%d\n”
,?Capital_Co?unt,Num_Co?unt) ;
}
?Count(char? *str, int? *result)
?{
int tem?p,I ; in?t