装订线
华南农业大学期末考试试卷( A卷)
2011学年第2学期
考试科目: 高级语言程序设计
考试类型:(闭卷) 考试时间: 90 分钟
考生须知:
1. 必须在答卷上正确填写班级、学号、姓名等内容。 2. 答案写在答卷上,写在试卷等其它地方不得分。 3. 试卷上出现的int类型变量均为4字节存贮。
4. 第三部分,上机考试,考试时间与地点另行安排,在笔试之前完成。
一、看程序写结果(共6题,每题4分)
1. #include \ main()
{
int a = 5.4; int b, c=25, d; b = a * 3; d = c/10.0;
printf(\}
请写出运行结果: 2. #include \ main()
{ int k=5,n=0; while(k>0) { switch(k) { default : break; case 1 : n+=k; case 2 : case 3 : n+=k; } k- -; printf(\ } }
请写出运行结果:
3. #include \
int f ( int n )
第1页 共6页
{ int c; if ( 1= = n ) c = 1;
else if ( 2= = n ) c = 3; else c = 2*f (n-1)-f (n-2); return c; }
main()
{ printf ( \ printf ( \ printf ( \}
请写出运行结果:
4. #include
main( )
{ char string[30]=\ char *p=&string[0], *p2=string+8; printf(\}
请写出运行结果:
5. #include \
int f(int a)
{ auto int b=0; static c=3; b=b+1; c=c+1;
return(a+b+c); }
int main()
{ int f(int); int a=2,i; for(i=0;i<3;i++)
printf(“%d\\n”,f(a)); }
请写出运行结果:
6. 有下面结构体类型定义, struct node { char info; struct node *link; };
假设已存在如下链表,
第2页 共6页
A B C D NULL head info link info link info link info link
装订以head为实参调用如下函数, void func(struct node *head)
{ struct node *p = head, *p2=NULL; int i=0;
while( p!= NULL)
{ putchar(p->info); p = p-> link; } putchar('\\n');
p = head;
while( p!= NULL)
{ if (++i%2==0) putchar(p->info); p = p-> link; }
}
请写出运行结果:
二、看程序填空题(共26空,每空2分)
线
1.下面程序判断某一年是否闰年,请填空。(提示:闰年为该年能被400整除,或能被4整除且不能被100整除) #include \main() { int year,leap; scanf (\ if (______【1】 ) { if ( year0= =0) { if( year@0= =0) leap = 1; else leap = 0; } else ______【2】 ; } else leap = 0; if (leap) printf(\ else printf(\ printf(\}
2. 下面程序实现由键盘输入一个3×4的矩阵,输出它的转置矩阵,请填空。
#include
第3页 共6页
{ }
int a[3][4],b[4][3],i,j; for(i=0;i<3;i++) for(j=0;j<4;j++) { scanf(\ ______【3】 ; }
for(i=0; i<4;i++)
{ for(j=0; ______【4】 ;j++) printf(\ printf(\}
3. 下面是求数列:
……
前n项和的程序,结果保留四位小数。 #include \main() { int i, n, a=2, b=1; float c, sum=______【5】 ; scanf(\ for(i=0; i 4. 下面程序将数组中数值前后对调,即第1个数组元素与最后一个对调,第2个数组元素与倒数第2个对调,…… #include int i, j, a[10]={3,7,9,11,0,6,7,5,4,2}; for(i=0;i<= 【7】 ;i++) { j= 【8】 ; temp=x[i];x[i]=x[j];x[j]=temp; } for(i=0;i<10;i++) printf(\ printf(\ 第4页 共6页 装订线} 5. 下面程序实现求出数组元素中的最大值,请填空。 #include \int main() { int c[10]={78,45,175,251,249,34,9,179,50,210}; int i,max; ______【9】________; for(i=1; i<10;i++) if(______【10】________ ) max = c[i]; printf(\, max); } 6. 在当前目录中存在文件名为\的文本文件,现要求你使用fopen函数命令打开该文件,读出里面的所有字符,只将其中的数字字符按先后顺序显示在屏幕上,请填空。 (如data.txt内容如下) 13 cats and 22 bikes (在屏幕上输出结果如下) 1322 程序如下,请填空, #include \main() { FILE *fp; char ch; if(( 【11】 )= =NULL) return 0; while((ch=fgetc(fp))!=EOF) { if ('0'<=ch && ch<='9') putchar(ch); } 【12】 ; } 7.下面程序实现输出2到200之间(包括2、200)的所有素数,请填空。 #include { int m,k,i; for(m=2;m<=200;m++) { k=sqrt(m); for(i=2;i<=k;i++) if(m%i= =0) break; if( 【13】 ) printf(\ 第5页 共6页
华农-2011年第二学期高级语言程序设计试卷(A)



