《C语言程序设计期末复习题(分析程序或程序段)新PDF.pdf》由会员分享,可在线阅读,更多相关《C语言程序设计期末复习题(分析程序或程序段)新PDF.pdf(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、第 7章 Visual C+ 编程基础页脚内容1 第三部分分析程序或程序段分析程序或程序段,给出下列程序的运行结果:1 #includemain()int i=16,j,x=6;j=i+ +1;x*=i=j;printf(“%dn”,j ,x);运行结果是:2#includemain()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 9: i+=1;case 10: i+=1;第 7章
2、Visual C+ 编程基础页脚内容2 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);第 7章 Visua
3、l C+ 编程基础页脚内容3 printf(%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; 运行结果是:
4、9#include void Func(void);第 7章 Visual C+ 编程基础页脚内容4 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: );g
5、ets(a);Inverse(a);printf(The inversed string 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;第 7章 Visual C+ 编程基础页脚内容5 运行时键盘上输入ASDFG,结果是:11. #include void Func(void);main() int i;for (i=0; i5; i+) Func(); v
6、oid Func(void) static int a = 1;int b = 2, c;c = a + b;a+;b+;printf(%3d, 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;第 7章 Visual C+ 编程基础页脚内容6 x+;x+
7、;printf(x=%dn,x);运行结果是:14.#includeint fun1(int x) x=20;return x;void fun2(int b4) int j;for(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
8、=2;iB=2;iC=iA+iB;printf(%5d,iC);第 7章 Visual C+ 编程基础页脚内容7 void fnSum2() int iC;iC=iA+iB;printf(%5d,iC);void 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);
9、for(k2=1;k2=k1*2-1;k2+)putchar(*);putchar(n);运行结果是:参考答案:第 7章 Visual C+ 编程基础页脚内容8 1 运行结果是: 17,1022运行结果是: d=203运行结果是: 134运行结果是: s=12345运行结果是: 106运行结果是: 8 139 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第 7章 Visual C+ 编程基础页脚内容9 0 1 2 315. 运行结果是: 4 110 216. 运行结果是:*