《C语言程序设计期末复习题(分析程序或程序段)新.doc》由会员分享,可在线阅读,更多相关《C语言程序设计期末复习题(分析程序或程序段)新.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、第 4 页 共 4 页第三部分 分析程序或程序段分析程序或程序段,给出下列程序的运行结果:4* 共* * :行 是行 0 是结= 果 :结 是运 是行) )( 是行 是行:结 行 结 果行 结 果00 结案是果 ) ( )*( +;* =( ) ( +; ( ) + = ( 是是结) ( ) ) , , ( ) + ( ) %( 0=,0= . :果 ; + ; = ) ) ,%= )( , 00= ( - ; ( 0= ( :),= + )(+0( + 0 0= , ( :果) +( ( ( : .:) ( + + , = + ; 0( ( ) 是是 输 = = - + ; = ) ( )
2、) )( )( ) _ ( ) _ 0:是)+ ) ( ( + ; () ( 是是 ( ) ”%( + ) ( 是) + =() , , ( = + 0 :果) % )+ ( =, ( . # )” )(0=( 0= 果)=( 00= = - 0; 0=, ,= ( . 果),%( + =: +: =: ) 0 ( 果果 ) %( ! ( 0-=)0 00 , ( 是是), ( + , ( 果行运列给程序序序程 序程运 +( 是 ( 0)0( %果 :+ = , 0;-= (=果 ( .( ( + : +( , + ) +( ) 是 ) ( ) 是0 ) ) ( - = + + : ( (+
3、:(, +(+) + ) 0 (0, =,) ;: . = (%) + ) ()是 + + =* ( (果案0果 结行 ) 运 : 是 : * * * -4-1#includemain()int i=16,j,x=6;j=i+ +1;x*=i=j;printf(“%d,%dn”,j,x); 运行结果是: 2#include main() int a,b,c,d;a=c=0;b=1;d=20;if(a) d=d-10;else if(!b) if(!c) d=25; else d=15;printf(“d=%dn”,d); 运行结果:3 main()int i=10;switch(i) case
4、 9: i+=1; case 10: i+=1; case 11: i+=1; default : i+=1; printf(“%d”,i);运行结果:4#includemain() int a=1,2,3,4,i,j,s=0; j=1; for(i=3;i=0;i-) s=s+ai*j; j=j*10; printf(s=%dn,s);运行结果:5func(int x) x=20; main()int x=10;func(x);printf(“%d”,x);运行结果:106 #include main() int x = 8 , y = 12;printf(%d %dn, x+, +y);p
5、rintf(%d %dn, x, y);运行结果是: 7#include void Func(int b)int j;for (j=0; j4; j+) bj = j;main()static int a = 5,6,7,8,i;Func(a);for (i=0; i4; i+) printf(%dn, ai);运行结果是: 8 #include main() int cube( int y ); int x; for(x=1;x=5;x+) printf(“%d ”, cube( x ) );int cube( int y ) return 2*y; 运行结果是:9#include void
6、 Func(void);main()int i;for (i = 0; i 2; i+)Func();void Func(void)static int times = 1;printf(Func() was called %d time(s).n, times+);运行结果是: 10.#include#include#define ARR_SIZE 80void Inverse(char str);main()char aARR_SIZE;printf(Please enter a string: ); gets(a); Inverse(a);printf(The inversed stri
7、ng is: );puts(a);void Inverse(char str)int len, i = 0, j;char temp; len=strlen(str);for (j=len-1; ij; i+, j-)temp = stri; strj = stri; strj = temp;运行时键盘上输入ASDFG,结果是:11. #include void Func(void);main()int i;for (i=0; i5; i+)Func();void Func(void)static int a = 1;int b = 2, c;c = a + b;a+;b+;printf(%3
8、d, c);运行结果是: 12. #include int fun(int x, int y) return x y ? x : y;main() int a=2,b=5,c=8; printf(%dn, fun(fun(a+c,b), a-c);运行结果是: 13. main()int i,j,x =0;for(i=0;i2;i+)x+;for(j=0;j3;j+)if(j%2) continue; x+;x+;printf(x=%dn,x);运行结果是: 14.#includeint fun1(int x) x=20; return x;void fun2(int b4) int j; f
9、or(j=3; j=0; j-) bj=j; main() int y,x = 10; int a4 = 1,2,3,4, k; y=2*fun1(x); printf(y=%dn, y); fun2(a); for(k=0; k4; k+) printf(%3d, ak); 运行结果是: 15.#include stdio.hint iA=100,iB=10;void fnSum1(int iA,int iB)int iC;iA=2;iB=2;iC=iA+iB;printf(%5d,iC);void fnSum2() int iC; iC=iA+iB;printf(%5d,iC);void
10、main() int iA=1,iB=1;register int iC; fnSum1(iA,iB); fnSum2(); iC=iA+iB; printf(%5d,iC);运行结果是:16#include stdio.h void main() int k1,k2; for(k1=1;k1=4;k1+) putchar(t); for(k2=1;k2=k1;k2+) putchar(b); for(k2=1;k2=k1*2-1;k2+) putchar(*); putchar(n); 运行结果是:参考答案:1运行结果是:17,1022运行结果是:d=203运行结果是:134运行结果是:s=12345运行结果是:106运行结果是:8 13 9 137运行结果是:01238运行结果是:2 4 6 8 109运行结果是:Func() was called 1 time(s).Func() was called 2 time(s).10. 运行结果是:GFDSA11. 运行结果是:3 4 5 6 712. 运行结果是:1013. 运行结果是:x=814.运行结果是:y=40 0 1 2 315.运行结果是:4 110 216. 运行结果是: * * * *