大一上c语言考试题及答案解析,大一c语言期末试及题参考答案.doc

大一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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值