11年C语言考试题B卷答案(3)

时间: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

11年C语言考试题B卷答案(3).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219