四、阅读分析题(本大题共6小题,每小题5分,共30分) 30.阅读下面程序,写出运行结果。 main( ) { int a=789, x,y,z; x=a/100; y=a/10-10*x; z=a-10*y-100*x printf(″%d,%o,%x,%d″, x,y,z,100*z+10*y+x); } 31.阅读下面程序,并回答问题: main( ) { int a,b,x,y; scanf(″%d,%d″,&a,&b); x=a*a+b*b if(x>100) {y=x/100;printf(″%d″,y);} else printf(″%d″,a+b); } (1)若程序运行时,输入6和9,输出结果是什么? (2)说明程序的功能。 32.阅读下面程序,并回答问题: main( ) { int u,v,a,b,t,r; u=24;v=16; if(u>v){t=u;u=v;v=t;} a=u;b=v; while ((r=b%a)!=0) {b=a;a=r;} printf(″a=%d\n″,a); } (1)程序输出结果是什么? (2)该程序完成什么功能? (3)若将while循环替换为do-while循环,请写出相应的程序段。 33.阅读下面程序,写出运行结果。 int a=5, b=5; chang1( ) { int a=4; printf(″a1=%d,b1=%d\n″,a,b++); } chang2(int a, int b) { a++; b--; } main( ) { chang1( );a++,b++;chang2(a,b); printf(″a2=%d,b2=%d\n″,a,b); } 34.阅读下面程序,写出运行结果。 #include <stdio.h> #include <string.h> main( ) { char p1,p2,srt[50]= ″abc″, str1[50]; p1=″abc″;p2=″abc″; puts(str); strcpy(str1,p1); p1=str1; printf(″%s\n″,strcat(p1,p2)); strcpy(str+1,p1); printf(″%s\n″,str); } 35.设有说明语句int*p; 请分析下面语句的含义: p=(int *)malloc(sizeof(int)); free(p); 五、程序设计题(本大题共2小题,每小题12分,共24分) 36.从键盘输入n*n个整型数(n≤20),组成n行n列数组,打印出其上三角数组。 37.用循环语句编程打印下列图案,并以ASCII码的形式写到c盘根目录下的1x.dat文件中。(第一行的″$″在第20列) $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
|