浙工大C语言程序设计期末试卷4.docVIP

  • 22
  • 0
  • 约6.41千字
  • 约 6页
  • 2021-01-19 发布于浙江
  • 举报
PAGE 1 PAGE 1 2008/2009二学期C程序设计试卷 说明:考生应将所有答案填写在答卷上,否则无效。 一、填空题(每小题2分,共20分) = 1 \* GB2 ⑴ 将a、b、c中最大值赋值到d的表达式是 。 = 2 \* GB2 ⑵ 若k=5、s=0,执行“while(k) s=s+k--;”后,s、k的值依次为 。 = 3 \* GB2 ⑶ 调用函数f(1.1,3)的返回值是 。 float f(float x,int n) { if(n==0) return 1; else return x*f(x,n-1); } = 4 \* GB2 ⑷ 程序中使用了C的库函数malloc,应包含的头文件为 。 = 5 \* GB2 ⑸ 下列程序段运行时的输出结果是 。 char s[]=Windows ,t[]=xp; printf(%s\n,strcat(s,t)); = 6 \* GB2 ⑹ 函数f定义如下,执行语句 sum=f(3)+f(5) 后,sum的值应为 。 int f(int m) { static int i=2; int s=0; for(;i=m;i++) s+=i; return s; } = 7 \* GB2 ⑺ 定义函数f返回m行n列float类型数组中最大值,其函数原型为 。 = 8 \* GB2 ⑻ 表达式 7|-2 的值为 。 = 9 \* GB2 ⑼ 若int类型变量a的当前值是7,执行“a=a2”后,a的值为 。 = 10 \* GB2 ⑽ 以“追加”方式打开文本文件e:\aa.txt的函数为 。 二、程序阅读题(每小题8分,共24分) 阅读下列程序,将运行时的输出结果写在答卷纸相应题号下。 1. #includestdio.h #include math.h void main() { double x[4]={123.45,-34.72,0.876,-765.3}; int i,y,k; for(i=0;i4;i++) { y=fabs(x[i]); k=0; while(y) { k++; y/=10; } printf(%d\n,k); } } 2. #include stdio.h #include math.h char *f(char *ss,int x) { int n; n=(int)log10(x)/log10(2)+1; ss[n]=\0; while(x!=0) { ss[--n]=char(x%2+0); x/=2; } return ss+n; } void main() { int i,a[4]={12,15,21,17}; char s[10]; for(i=0;i4;i++) puts(f(s,a[i])); } 3. 运行时的输入数据为: 10↙ 5↙ 24↙ 6↙ 35↙ -4↙ 0↙ #include stdio.h #include stdlib.h struct node { int x; node *next; }; void main() { node *head,*p1,*p2; int n=0; float ave=0; while(1) { p2=(node*)malloc(sizeof(node)); scanf(%d,p2-x); ave+=p2-x; if(n++==0) head=p1=p2; else {p1-next=p2;p1=p2;} if(p2-x==0) { p2-next=NULL; break; } } ave/=n; p1=head; while(p1-next){ if(p1-xave) printf(%d\n,p1-x); p1=p1-next; }

文档评论(0)

1亿VIP精品文档

相关文档