11年C语言考试题B卷答案(3)
时间:2025-04-21
时间:2025-04-21
#include <stdio.h>
main ()
{ int i,j,a[3][3]={1,2,3,4,5,6,7,8,9}; for (i=1; i<3;i++)
for(j=1; j<3; j++) printtf(”%d”, a[i][j]); printf(”\n”); }
3.运行以下程序,写出输出结果。agaagag #include <stdio.h> #include <string.h> fun(char *w, int n) { char t,*s1,*s2; s1=w; s2=w+n-1; while(s1<s2) { t=*s1++; *s1=*s2--; *s2=t; }
} main( )
{ char a[]="abcdefg",*p=a; fun(p,strlen(p)); puts(p);
}
4、阅读结构体程序,写出输出结果。
#include <stdio.h> // 输出结果为( a, 11,22, 18.750000 )main()
{ struct stType { char chA; short shB; int iC; float fD; };
struct stType stE={'A',1,2,18.75},*p=&stE;
printf("%C,%d,%d,%f\n",stE.chA+32,p->shB+10,(*p).iC+20,stE.fD); }
5、执行以下程序,打开file.dat文件,文件中的数据为( end ) #include <stdio.h>
void writeStr(char *fn,char *str) { FILE *fp; fp = fopen(fn, "w"); fputs(str,fp); fclose(fp); } main( ) { writeStr("t1.dat","start"); writeStr("t1.dat","end");
}
六、编程题题( 共5小题,每题4分,共20分 )
1、已知双精度型变量x = 4.56789,试将该数精确到小数点后的第2位。 #include <stdio.h> main() {
double x = 4.56789; x = (int)(x*1000+.5)/1000.0;
printf("%f\n",x);
}
2、编制用辗转除法求最大公约数的程序,已知两个整数分别为14、63,编程求最大公约数。7 解:
#include <stdio.h>
main( )
{ int a , b, c, t , r ; scanf(“%d,%d”, &a, &b ) ; if(a > b ) { t = a; a = b; b = a; } r = a % b;
while( r! = 0 ) {a = b;b = r;r = a % b;}
3
上一篇:高一第二学期第一次生物月考
下一篇:钢板许用应力查询完全EXCEL