大一c语言期末试题及答案.pdfVIP

  • 342
  • 2
  • 约1.26万字
  • 约 12页
  • 2021-06-21 发布于湖南
  • 举报
2004 级信息学院《 C语言设计》考试试题 一、判断下列语句或程序的对错。 10 分 √ 1 int x=y=z= ’0’; (×) y,z 没有定义 2 #include stdio.h ; (×) 不能有分号, #开头的结尾均不能有分号; 3 printf( “%s\n”, ”c language ”); (√) 4 float a[100]; int *p=a; (×) 数据类型不匹配 5 char str[20]; 6 int data[4]={0,1,2,3,4}; (×)五个元素,但是只有四个单元 7 float x=1.45e+310L; (×)数值越界 8 int xyz-1=2; (×) 9 int x= ‘\xae ’ ; ( √) 10 int *p,a[2][3] ; p=a ; (×) 数据类型不匹配 二 计算下列表达式的值 10 分 设 unsigned int a=10,b=17,c=5,d=3; float f ; (1)f=b/c ( 3.0 ) (2)!(a+b)+c-1b+c/2 ( 1 ) (3)(a^b)+(c1+d) ( 0x1b ) (4)a+=b%=a=b ( 17 ) (5)a=2,b=a*++b ( 2 ) 三 程序改错 10 分 (1) 求两个浮点数的平方和及平方差 #include stdio.h float calculate (float x,float y,float *sub); 添加函数原型声明 main () { float a,b ; float add_reasult, sub_result ; scanf ( “%f,%f ”,a,b) ; add_result=calculate(a,b,sub_result) ; printf( “a*a+b*b=%d,a*a-b*b=%d\n ”,add_result,sub_result) ; } float calculate (float x,float y,float *sub) 添加函数类型 { float *temp; 应该直接定义为变量 float temp; sub=a*a-b*b ; *sub=a*a-b*b; temp = a*a+b*b; return *temp; return temp } (2 ) 统计 N 个字符中大写字母和数字字符的个数 #include stdio.h #define N 5 Count(char *str,int *result); 添加函数声明 main () { char string[N][80]; char i; int Capital_Count =0,Num_Count=0;需要初始化为 0 for(i=0;iN;i++) scanf( “%s”,

文档评论(0)

1亿VIP精品文档

相关文档