分析程序写出结果.doc

上传人:scccc 文档编号:12475332 上传时间:2021-12-04 格式:DOC 页数:17 大小:76.50KB
返回 下载 相关 举报
分析程序写出结果.doc_第1页
第1页 / 共17页
分析程序写出结果.doc_第2页
第2页 / 共17页
分析程序写出结果.doc_第3页
第3页 / 共17页
亲,该文档总共17页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《分析程序写出结果.doc》由会员分享,可在线阅读,更多相关《分析程序写出结果.doc(17页珍藏版)》请在三一文库上搜索。

1、五、阅读程序(26)(一).写出下列程序的输出结果是(5X 2)1. #include<iostream>using n amespace std;int mai n() int i=1,sum=0;dosum += i;i+;while(i<=100)cout« ”um=”v<sumv<endl;return 0;_ sum=50502. #include<iostream>using n amespace std;int mai n() char str1 = ”love chi na!”,str220,*p1,*p2;p1= str1;

2、p2=str2;for(;*p1!='0 'p1+,p2+)*p2 =*p1;*p2= '0 p仁 str1;p2=str2;cout<< ” str1 is:” <vp1v<e ndl;cout<< ” str2 is:” <vp2v<e ndl;return 0;str仁 ” I love china! ” str2= ” I love chi#in clude<iostream>using n amespace std;int mai n()char c1= ' a' ,c2= '

3、 d' ,c3= ' f'c1+=2;c2+=2;c3+=2;cout<<c1<<c2<<c3<<e ndl;return 0;运行结果:cfh2. 写出下列程序的输出结果。#in clude<iostream>using n amespace std;int i,j,m, n;int mai n() i=5;j=6;m=+i+j+;vvnvven dl;n=(+i)+(+j)+m;coutvvivv ' t ' vvjvv ' t ' <<m<< t &

4、#39; return 0;运行结果:7812273. 写出下列程序的输出结果。#in clude<iostream>using n amespace std;int mai n()const int n=5;int a n=9,6,3,4,5,i,t;for(i=0;i< n/2;i+)t=ai;ai=a n-i-1;a n-i-1=t; for(i=0;i <n ;i+) cout<<ai<< ”“;cout«e ndl; return 0;运行结果:543691. struct abc int a, b, c; ;mai n()

5、struct abc s2=1,2,3,4,5,6;int t;cout<<s0.c<< '';t=s0.a+s1.b;cout«t; 3_62.void swap(i nt *p1, int *p2)int *p;p=p1;p 仁p2;p2=p; mai n() int a=3,b=5;int *pt1,*pt2;pt1= &a;pt2=&b;cout<<*pt1<< ',,<v*pt2v<endl; swap(pt1,pt2);cout<<*pt1<< &#

6、39;,,<v*pt2v<endl; 3.53.51、#in clude<iostream.h>int t()static int i=100;i+=5;return i;运行结果:i=105i=1002、#i nclude<iostream.h>void swap 1(i nt *p1, i nt *p2)int t;t=*p1;*p1=*p2;*p2=t;void swap 2(i nt & p1, i nt & p2)int *t;t=p1;p 1=p2;p2=t;void ma in (void)int x,y;int a,b;x=1

7、0,y=20;swap1(&x,& y);void mai n()cout<<”= ”vvt()v< 'n' cout«”i= ”vvt()v< 'n' swap2(a,b); coutvv"x="v<xvv",y="vvyvv'n' coutvv"a="v<avv",b="vvbvv'n' a=100,b=200;运行结果是:x=20,y=10 a=100,b=2001、#include&

8、lt;iostream.h>int t()static int i=100;i+=5;return i;void mai n()cout<< ”= ”<<t()<< 'n 'cout<< "i= ”<<t()<< 'n '运行结果:i=1053#in clude<iostream.h>struct sint m;float x;void swap(s s1, s s2) s t;t=s1;s仁 s2;s2=t;s fun(s s1, s s2)s t;t.m=s1

9、.m+s2.m;t.x=s1.x+s2.x;return t;i=1102、#include <iostream.h>void main( void )int i, x,num;cin> >x;while(x) nu m=x%10;cout< <num;x=x/10;若输入x为145734则输出为:437541cout<< ”1.m= "<<r1.m<< ' '< ”1.x= ” <<r1.x<< 'n'cout<< ”2.m= ”<

10、<r2.m<< ' '< ”r2.x= ”<<r2.x<< 'ns sum;sum=fun( r1,r2);cout<< "sum.m= "<<sum.m<< 't '<"su m.x= "<<sum.x<< 'nvoid mai n()s r仁100,250.5,r2=200,350.5;swap (r1,r2);执行程序后输出:r1.m=100r1.x=250.5r2.m=200sum.m=

11、300r2.x= 350.5sum.x=6014、# in elude“ iostream.h ”void mai n()static char a=” Radio&TV Universitystatic int b8=6,8,9,2;char *p=a;int *q;q=b;cout«e ndl;<<p2<<e ndl;<<*q+;cout<<a1<< ' , ' vv*pvv' , ' vv*(a+6)v< *q=*(q+1)+2;*(q+2)=*q*2;q+;cout &l

12、t;<b5<< ' , ' vv*b<v' , ' <<b1<< '执行程序后输出:a,R,T,d0,10,8,81. #include<iostream>using n amespace std;int mai n()char c1= ' A' ,c2= ' D' ,c3= ' k'c1+=2;c2+=3;c3-=4;coutvvclvv “ ” vvc2v<“ <<c3<<endl;return 0;_CGg2.

13、#in clude<iostream>using n amespace std;int main()int i,j,m, n;i=361;j=i/100;m=i%10; n=(i%1OO)/1O;<<e ndl;if(i=j*j*j+m*m*m+n*n*n) cout<<i<<” 是水仙花数”else coutvvivv ”不是水仙花数” <<e ndl;return 0;361 不是水仙花数 _3 #in clude<iostream>using n amespace std;int main()const int n=

14、9;int an=9,6,3,4,5, 45, 32, 78, 21,i,t;for(i=0;i< n/2;i+)t=ai;ai=a n-i-1;a n-i-1=t;for(i=0;i< n;i+)cout<<ai<< ”“;cout«e ndl;return 0;输出结果是:21 78 32 45 5 4 3 6 94有如下程序:#in elude <iostream.h>using n amespace std;class A public: A() cout << "A" ;class B publ

15、ic: B() cout << "B" ;class C : public A B b;public:C( ) cout << "C" ;int main() C obj;return 0;执行后的输出结果是:ABC5. # include <iostream>using n amespace std;void swap( int *p1,i nt *p2) int *p;p=p1;p1=p2;P2=P;mai n() int a=3,b=5;int *pt1,*pt2;pt1= &a;pt2=&b;c

16、out<<*pt1<< ' , ' <v*pt2v<endl;swap(pt1,pt2);cout<<*pt1<< ' , ' <<*pt2<<endl;运行结果:33, 5,56. #i nclude <iostream> #include <iomanip> using n amespace std; int main()cout.fill('*');cout.width(6);cout << 123 << en

17、dl;return 0;运行结果:#1233. #include<iostream> using n amespace std;int age(i nt);int mai n() cout<<age(3)<<e ndl;return 0;int age(i nt n) int c;if(n= =1)c=8;elsec=age( n-1)+2;return (c);运行结果:124. #include<iostream> using n amespace std; int mai n() int a5=3,5,7,9,6;int i,*p=a;fo

18、r(p=a;pv(a+4);p+) cout<v*pv< ” cout«e ndl;return 0;运行结果:3 5 7 91、#include<iostream>using n amespace std;int mai n() float add(float,float);float a=12.68,b=56.45;c=add(a,b);cout<v”sum=”vvcvve ndl;float add(float x,float y) float 乙z=x+y;return (z);运行结果sum=69.13 :2、#include<iostr

19、eam>using n amespace std;return 0;int age(i nt);int mai n() cout<<age(3)<<e ndl;return 0;int age(i nt n) int c;if(n= =1)c=8;else c=age(n-1)+2; return (c);运行结果:123、#include<iostream>using n amespace std;int mai n() int a5=3,5,7,9,6;int i,*p=a;for(p=a;pv(a+4);p+) cout<v*pv<

20、”“cout«e ndl;return 0;运行结果:3 5 71. #include <iostream>using n amespace std;int main()void fun (i nt, in t);int i=2,x=5,j=7;fun (j,6);coutvvivv ' 'vjvv< x;void fun (i nt i, i nt j)int x=7;coutvvivv ' 'vjvv '' vx;输出结果是:7 6 72.当运行以下程序时,从键盘输入a pple<CR>c at<CR>( <CR> 表示回车)#in clude<iostream>using n amespace std;int mai n() char s80,*p;cin> >s;p=s;while(*(+p)!= 0')if (*p= '"'break;else p+; cin> >p;cout«p;return 0; at第 14 页共14页

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1