C++语言程序设计课程的程序分析练习题

上传人:e****s 文档编号:245509397 上传时间:2022-01-25 格式:DOC 页数:18 大小:64.50KB
返回 下载 相关 举报
C++语言程序设计课程的程序分析练习题_第1页
第1页 / 共18页
C++语言程序设计课程的程序分析练习题_第2页
第2页 / 共18页
C++语言程序设计课程的程序分析练习题_第3页
第3页 / 共18页
C++语言程序设计课程的程序分析练习题_第4页
第4页 / 共18页
C++语言程序设计课程的程序分析练习题_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《C++语言程序设计课程的程序分析练习题》由会员分享,可在线阅读,更多相关《C++语言程序设计课程的程序分析练习题(18页珍藏版)》请在金锄头文库上搜索。

1、C+语言程序设计课程的程序分析练习题徐孝凯 一、写出下列每个程序运行后的输出结果 1. #include #include void main() int x=20, y=6, z; char op=+; switch(op) case +: z=x+y; break; case -: z=x-y; break; default: cout操作符op出错,退出运行!;exit(1); cout”z=”zendl; 运行结果: 2. #include #include void main() char* a5=student,worker,cadre,soldier,apen; unsigned

2、 int n=strlen(a0); /求字符串a0的长度 for(int i=1;in) n=strlen(ai); coutnendl; 运行结果: 3. #include int WF(int x, int y) x=x+y; y=x+y; return x+y; void main() coutWF(8,5)endl; 运行结果: 4. #include const int N=9; void main() int aN=2,4,6,8,10,12,14,16,18; int s=0; for(int i=0; iN; i+) if(ai%3=0) s+=ai; cout”s=”sen

3、dl; 运行结果: 5. #include void main() int* d=new int5; int i,s=0; for(i=0;i5;i+) di=2*i+1; for(i=0;i5;i+) s+=di; cout3*sendl; deleted; 6. #include void SB(char ch) switch(ch) case A: case a: cout优! ; break; case B: case b: cout良! ; break; case C: case c: cout通过! ; break; default: cout不通过!;break; void ma

4、in() SB(A); SB(c); coutendl; 运行结果: 7. #include void main() int a6=36,25,48,14,55,40; int x=a0; for(int i=1;ix) x=ai; cout”x=”xendl; 运行结果: 8. #include void main() int a6=32,53,27,19,12,45; for(int *p=a; pa+6; p+) if(*p%3=0) cout*p ; coutendl; 运行结果: 9. #include int* LG(int m) int* a=new int(m+5); retu

5、rn a; void main() int n1=12; int *b=LG(n1); cout*bendl; delete b; 运行结果: 10. #include #include struct Worker char name15; int age; float pay; ; void main() Worker x; strcpy(x.name, WeiRong); x.age=45; x.pay=3275; coutx.name x.age x.payendl; 运行结果: 11. #include void main() int n=5, sum=0; while(n) sum+

6、=n; n-; cout”sum=”sumendl; 运行结果: 12. #include const int N=6; void main() int aN=76,83,54,62,40,65; int c1, c2; c1=c2=a0; for(int i=1;ic1) c1=ai; else if(aic2) c2=ai; coutc1 c2endl; 运行结果: 13. #include void main() int a8=4,8,15,16,20,30,48,62; int *p=a; while(pa+8) cout*p ; p+=3; coutendl; 运行结果: 14.#i

7、nclude int LF(int x, int y) x=x+y; y=x+y; return x+y; void main() int x=5, y=8; coutLF(1,2) LF(3,4)endl; 运行结果: 15. #include class A int a,b; public: A() a=b=0; A(int aa, int bb) a=aa; b=bb; couta bendl; ; void main() A x,y(3,4); 运行结果: 16. #include void main() int n=4,y=1; while(n-) y*=3; couty=yendl; 运行结果: 17. #include void main() int a8=2,8,10,5,12,7,9,20; int c=0, i=0; while(i10) c+; i+; coutc=cendl; 运行结果: 18. #include void main() int a5=3,6,9,12,8; for(int *p=a; p8) cout

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 经济/贸易/财会 > 经济学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号