写出程序分析程序写出结果_第1页
写出程序分析程序写出结果_第2页
写出程序分析程序写出结果_第3页
写出程序分析程序写出结果_第4页
写出程序分析程序写出结果_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

写出程序分析程序写出结果 五、程序(26) (一). 写出下列程序的输出结果是(52) 1#include using namespace std; int main( ) int i=1,sum=0; do sum += i; i+; while(i cout _sum=5050_ 2. #include using namespace std; int main( ) char str1 =”I love china!”,str220,*p1,*p2; p1=str1;p2=str2; for(;*p1!=?0?;p1+,p2+) *p2=*p1; *p2=?0?; p1=str1;p2=str2; cout _str1=”I love china!”_ _str2=”I love china!”_ #include using namespace std; int main() char c1=a ,c2=d ,c3=f ; c1+=2; c2+=2; c3+=2; cout 运行结果:cfh 2. 写出下列程序的输出结果。 #include using namespace std; int i,j,m,n; int main() i=5; j=6; m=+i+j+; n=(+i)+(+j)+m; cout 运行结果:7 8 12 3. 写出下列程序的输出结果。 #include using namespace std; int main() const int n=5; int an=9,6,3,4,5,i,t; for(i=0;i 27 t=ai;ai=an-i-1;an-i-1=t; for(i=0;icout 运行结果:5 4 3 6 9 1struct abc int a, b, c; ; main() struct abc s2=1,2,3,4,5,6; int t; cout _3_ _6_ 2. void swap(int *p1,int *p2) int *p; p=p1;p1=p2;p2=p; main() int a=3,b=5; int *pt1,*pt2; pt1=&a; pt2=&b; cout cout _3.5_ _3.5_ 1、 #include int t() static int i=100; i+=5; return i; 运行结果: i=105 i=100 2、 #include void swap1(int *p1, int *p2) int t; t=*p1;*p1=*p2;*p2=t; void swap2(int &p1, int &p2) int *t; t=p1;p1=p2;p2=t; void main(void) int x,y; int a,b; x=10,y=20; swap1(&x,&y); a=100,b=200; void main() cout swap2(a,b); cout运行结果是: x=20,y=10 i=110 2、 #include void main(void ) int i, x,num; cinx; while(x) num=x%10; cout 若输入x 为145734 则输出为:437541 cout cout sum=fun(r1,r2); cout a=100,b=200 1、#include int t() static int i=100; i+=5; return i; void main() cout 运行结果:i=105 3#include struct s int m; float x; ; void swap(s s1, s s2) s t; t=s1; s1=s2; s2=t; s fun(s s1, s s2) s t; t.m=s1.m+s2.m; t.x=s1.x+s2.x; return t; void main() s r1=100,250.5,r2=200,350.5; swap(r1,r2); 执行程序后输出: r1.m=100 r1.x=250.5 r2.m=200 r2.x= 350.5 sum.m=300 sum.x=601 4、include “iostream.h” void main() static char a=”Radio&TV University”; static int b8=6,8,9,2; char *p=a; int *q; q=b; cout coutcout 执行程序后输出:a,R,T,d 0,10,8,8 1 #include using namespace std; int main() char c1=A ,c2=D ,c3=k ; c1+=2; c2+=3; c3-=4; cout _C_G_g_ 2. #include using namespace std; int main() int i,j,m,n; i=361; j=i/100;m=i%10;n=(i%100)/10; if(i=j*j*j+m*m*m+n*n*n) cout 不是水仙花数_ 3 #include using namespace std; int main() const int n=9; int an=9,6,3,4,5,45,32,78,21,i,t; for(i=0;i t=ai;ai=an-i-1;an-i-1=t; for(i=0;i cout输出结果是:21 78 32 45 5 4 3 6 9 4有如下程序: #include using namespace std; class A public: A( ) cout ; class B public: B( ) cout ; class C : public A B b; public: C( ) cout int main( ) C obj; return 0; 执行后的输出结果是:ABC 5include using namespace std; void swap(int *p1,int *p2) int *p; p=p1; p1=p2; p2=p; main() int a=3,b=5; int *pt1,*pt2; pt1=&a; pt2=&b; cout cout 运行结果:3,5 3,5 6.#include #include using namespace std; int main( ) cout.fill(*); cout.width(6); cout.fill(#); cout return 0; 运行结果:#123 3#include using namespace std; int age(int); int main( ) coutint age(int n) int c; if(n= =1) c=8; else c=age(n-1)+2; return (c); 运行结果:12 4#include using namespace std; int main( ) int a5=3,5,7,9,6; int i,*p=a; for(p=a;p cout cout 运行结果: 3 5 7 9 1、#include using namespace std; int main() float add(float,float); float a=12.68,b=56.45; c=add(a,b); cout float add(float x,float y) float z; z=x+y; return (z); 运行结果sum=69.13: 2、#include using namespace std; int age(int); int main( ) coutreturn 0; int age(int n) int c; if(n= =1) c=8; else c=age(n-1)+2; return (c); 运行结果:12 3、#include using namespace std; int main( ) int a5=3,5,7,9,6; int i,*p=a; for(p=a;p cout cout 运行结果:3 5 7 return 0; void fun(int i, int j) int x=7; cout 1#include using namespace std; int main( ) void fun(int,int); int i=2,x=5,j=7; fun(j,6); cout 输出结果是:7 6 7

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论